ICPC 国内予選2018C 超高層ビル「みなとハルカス」AOJ1626
解法:しゃくとり法(?)(しゃくとりほうがどんなものなのかはっきり覚えてないけどたしかそう
#include <bits/stdc++.h> #include <map> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; const ll MOD=1e9+7; const ll INF=1e18; int dx[]={1, -1, 0, 0}; int dy[]={0, 0, 1, -1}; int main(){ int n; while(1){ cin >> n; if(n == 0)break; int a = 1,b = 1,sum = 1; while(1){ if(sum < n){ b++; sum+=b;} else if(sum > n){ sum-=a;a++;} else break; } cout << a << " " << b-a+1 << endl; } }