fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int gcd(int u, int v) {
  7. if(u==v) return u;
  8. if(u==0) return v;
  9. if(v==0) return u;
  10. if(~u & 1) {
  11. if(v & 1) return gcd(u>>1, v);
  12. else return gcd(u>>1, v>>1)<<1;
  13. }
  14. if(~v & 1) return gcd(u, v>>1);
  15. if(u>v) return gcd((u-v)>>1, v);
  16. return gcd((v-u)>>1, u);
  17. }
  18.  
  19. int main() {
  20. int a, b, x, y, g, Bx, By, B;
  21. scanf("%d%d", &a, &b);
  22. for(int i=0; i<a; i++) {
  23. for(int j=0; j<a; j++) {
  24. if(pow(i, 2) + pow(j, 2)==pow(a, 2)) {
  25. x=i, y=j;
  26. g=gcd(x, y);
  27. Bx=-y/g;
  28. By=x/g;
  29. B=sqrt(pow(Bx, 2) + pow(By, 2));
  30. if(b%B==0 && sqrt(pow(By*b/B-y, 2))!=0 && sqrt(pow(Bx*b/B-x, 2))!=0) {
  31. printf("YES\n");
  32. printf("0 0\n");
  33. printf("%d %d\n", x, y);
  34. printf("%d %d\n", Bx*b/B, By*b/B);
  35. return 0;
  36. }
  37. }
  38. }
  39. }
  40. printf("NO");
  41. return 0;
  42. }
Success #stdin #stdout 0s 3300KB
stdin
15 20
stdout
YES
0 0
12 9
-12 16