Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #pragma comment(linker, "/stack:16777216")
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <list>
  7. #include <iterator>
  8. #include <set>
  9. #include <queue>
  10. #include <iostream>
  11. #include <sstream>
  12. #include <stack>
  13. #include <deque>
  14. #include <cmath>
  15. #include <memory.h>
  16. #include <cstdlib>
  17. #include <cstdio>
  18. #include <cctype>
  19. #include <algorithm>
  20. #include <utility>
  21. #include <fstream>
  22. #include <time.h>
  23. using namespace std;
  24.  
  25. #define FOR(i, a, b) for(int i = (a); i < (b); ++i)
  26. #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
  27. #define REP(i, N) FOR(i, 0, N)
  28. #define RREP(i, N) RFOR(i, N, 0)
  29. #define FILL(A,value) memset(A,value,sizeof(A))
  30. #define ALL(V) V.begin(), V.end()
  31. #define SZ(V) (int)V.size()
  32. #define PB push_back
  33. #define MP make_pair
  34. #define y0 gfdssdfer
  35. #define y1 wetgwervbwqr
  36.  
  37. typedef long long Int;
  38.  
  39. const int MAX = 2007;
  40. const int MOD = 1000000007;
  41. const int INF = 1000000000;
  42.  
  43.  
  44. int main()
  45. {
  46. freopen("in.txt" , "r" , stdin);
  47. // freopen("out.txt" , "w" , stdout);
  48.  
  49. int t;
  50. cin >> t;
  51. FOR(ttt,0,t)
  52. {
  53. int A = 0;
  54. int B = 2 * INF;
  55.  
  56. int N;
  57. scanf("%d" , &N);
  58.  
  59. for(int i = 2; i * i <= 2 * N; ++i)
  60. {
  61. if ((2 * N) % i == 0)
  62. {
  63. int y = i;
  64. int x = (2 * N) / i;
  65. if ((x + y) % 2 == 1)
  66. {
  67. int b = (x + y - 1) / 2;
  68. int a = (x - b);
  69. if (a >= 0 && b >= 0)
  70. {
  71. if (b - a < B - A)
  72. {
  73. A = a;
  74. B = b;
  75. }
  76. }
  77. }
  78. }
  79. }
  80.  
  81. if (B == 2 * INF)
  82. {
  83. printf("IMPOSSIBLE\n");
  84. }
  85. else
  86. {
  87. printf("%d = ", N);
  88. FOR(i,A,B)
  89. {
  90. printf("%d + ", i);
  91. }
  92. printf("%d\n", B);
  93. }
  94.  
  95. }
  96.  
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement