fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int NWD(int a, int b){
  5. int r = a % b;
  6. while(r != 0){
  7. a = b;
  8. b = r;
  9. r = a % b;
  10. }
  11. return b;
  12. }
  13.  
  14. int main(){
  15. int n, m;
  16. cin >> n >> m;
  17. int d = NWD(n, m);
  18. cout << max(2, d) << "\n";
  19. int x = -1, y = -1;
  20. for(int i = 1; i < d; ++i){
  21. int j = d - i;
  22. if(NWD(i, n) == 1 && NWD(j, m) == 1){
  23. x = i;
  24. y = j;
  25. break;
  26. }
  27. }
  28. if(d == 1){
  29. cout << "GP";
  30. } else {
  31. cout << string(x, 'G');
  32. cout << string(y, 'P');
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5296KB
stdin
720 660
stdout
60
GPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP