immuntasir

11254

Feb 25th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5.     long long int a,b,c,i,j,m,n1,num,found;
  6.     double n,det;
  7.     while (scanf("%lld",&num)) {
  8.         if (num<0) break;
  9.         found = 0;
  10.         a=num;
  11.         b=num;
  12.         c = (num/2) +1;
  13.         for (m=0;m<=c&&!found;m++) {
  14.             det = sqrt(1+4*(m*m+m+2*num));
  15.             n = (-1+det)/2;
  16.             n1 = n;
  17.             if (n1==n) {
  18.                 found =1;
  19.                 a = n;
  20.                 b = 1+m;
  21.             }
  22.         }
  23.         printf("%lld = %lld + ... + %lld\n",num,b,a);
  24.     }
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment