1120. Sum of Sequential Numbers
Time Limit: 1.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
There is no involute formulation concerning factitiously activity of SKB Kontur in this problem. Moreover, there is no formulation at all.
Input
There is the only number N, 1 ≤ N ≤ 109.
Output
Your program is to output two positive integers A and P separated with a space such that:
- N = A + (A + 1) + … + (A + P − 1).
- You are to choose a pair with the maximal possible value of P.
Sample
input | output |
---|---|
14 |
2 4 |
剪一下枝就可以了~
#include <iostream>
#include <cmath>
using namespace std;
bool temp(int p, int n)
{
if ((n*2) % p != 0)
return 0;
int a = (n*2) / p + 1 - p;
if (a <= 0 || (a&1))
return 0;
return 1;
}
int main()
{
int n, p;
cin>>n;
p = sqrt(n*2.0);
while (!temp(p, n))
p--;
cout<<(n*2/p + 1-p)/2<<" "<<p<<endl;
}