fork(2) download
  1. #include <set>
  2. #include <map>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iomanip>
  14. #include <complex>
  15. #include <iostream>
  16. #include <algorithm>
  17.  
  18. #include <ctime>
  19. #include <deque>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <utility>
  23. #include <cassert>
  24. using namespace std;
  25.  
  26. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  27. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  28. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  29. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  30. #define SZ(S) ((int) ((S).size()))
  31.  
  32. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  33. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  34. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  35.  
  36. vector< pair<int, pair<int,int> > > all;
  37.  
  38. int mysqrt(int x) {
  39. int a = sqrt(x);
  40. while (a * a < x) ++a;
  41. while (a * a > x) --a;
  42. return a;
  43. }
  44.  
  45. int S, P;
  46. #define sqr(x) ((x) * (x))
  47. bool check(int x1, int y1, int x2, int y2, int c) {
  48. if (c*c == sqr(x1-x2) + sqr(y1-y2)) {
  49. cout << "Dream" << endl << 0 << ' ' << 0 << endl << x1 << ' ' << y1 << endl << x2 << ' ' << y2 << endl;
  50. return true;
  51. }
  52. return false;
  53. }
  54.  
  55. void solve() {
  56. long long prod = S * (long long) S / (P/2);
  57. FOR(a,1,P/2-1) if (prod % (P/2 - a) == 0) FOR(b,1,P-a-1) {
  58. int c = P - a - b;
  59. if (c < 0 || c > P) continue;
  60.  
  61. long long p = P / 2;
  62. if (S * (long long) S / 4 != p * (p-a) * (p-b) * (p-c)) continue;
  63.  
  64. int ia = lower_bound(all.begin(), all.end(), make_pair(a, make_pair(0, 0))) - all.begin();
  65. int ib = lower_bound(all.begin(), all.end(), make_pair(b, make_pair(0, 0))) - all.begin();
  66. int saveib = ib;
  67.  
  68. while (all[ia].first == a) {
  69. ib = saveib;
  70. while (all[ib].first == b) {
  71. int x = all[ia].second.first, y = all[ia].second.second, z = all[ib].second.first, t = all[ib].second.second;
  72. REP(turn,2) {
  73. REP(turn2,2) {
  74. REP(turn1,2) {
  75. if (check(x, y, z, t, c)) return ;
  76. if (check(x, y, -z, t, c)) return ;
  77. if (check(x, y, z, -t, c)) return ;
  78. if (check(x, y, -z, -t, c)) return ;
  79. swap(z, t);
  80. }
  81. swap(x, y);
  82. }
  83. swap(x, z);
  84. swap(y, t);
  85. }
  86. ++ib; if (ib == all.size()) break;
  87. }
  88. ++ia; if (ia == all.size()) break;
  89. }
  90. }
  91. cout << "Flag" << endl;
  92. }
  93.  
  94. int main() {
  95. ios :: sync_with_stdio(false); cin.tie(NULL);
  96. cout << (fixed) << setprecision(6);
  97. FOR(i,1,10000) FOR(j,i+1,10000) {
  98. int cur = i*i + j*j;
  99. int k = mysqrt(cur);
  100. if (k*k == cur) all.push_back(make_pair(k, make_pair(i, j)));
  101. }
  102. FOR(i,1,10000) all.push_back(make_pair(i, make_pair(0, i)));
  103. sort(all.begin(), all.end());
  104. while (cin >> S >> P) {
  105. if (S % 2 == 1) cout << "Flag" << endl;
  106. else if (P % 2 == 1) cout << "Flag" << endl;
  107. else if (S *(long long) S % (P/2)) cout << "Flag" << endl;
  108. else solve();
  109. }
  110. return 0;
  111. }
  112.  
  113.  
Success #stdin #stdout 2.22s 3552KB
stdin
12 12
stdout
Dream
0 0
0 3
4 0