fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long gcd(long a, long b){
  5. while (a && b)
  6. if (a > b) a%=b;
  7. else b%=a;
  8. return a+b;
  9. }
  10.  
  11. long calc(long nok, long first){
  12. if (nok % first != 0)
  13. return -1;
  14. long res = nok/first;
  15. long g = 1;
  16. long tmp;
  17. while ( (tmp = gcd(first, res)) != g){
  18. g = tmp;
  19. res = nok/first * g;
  20. }
  21. return res;
  22. }
  23.  
  24. int main() {
  25. // your code goes here
  26. for (int s = 1; s <= 500; s++)
  27. for (int v = s; v <= 500; v++){
  28. long gd = s*v/gcd(s,v);
  29. long a1 = calc(gd,s);
  30. if (a1 == -1){
  31. cout <<"wtf"<<endl;
  32. }
  33. if (a1 > v){
  34. cout <<"not a min [" <<s<<" "<<v<<"] "<<a1<<endl;
  35. }
  36. if (a1*s/gcd(a1,s) != gd){
  37. cout <<"wa [" <<s<<" "<<v<<"]"<<a1<<endl;
  38. }
  39. a1 = calc(gd,v);
  40. if (a1 == -1){
  41. cout <<"wtf"<<endl;
  42. }
  43. if (a1 > s){
  44. cout <<"not a min [" <<s<<" "<<v<<"]"<<a1<<endl;
  45. }
  46. if (a1*v/gcd(a1,v) != gd){
  47. cout <<"wa [" <<s<<" "<<v<<"]"<<a1<<endl;
  48. }
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0.08s 4472KB
stdin
Standard input is empty
stdout
Standard output is empty