Advertisement
a53

VerifProgresie

a53
Nov 16th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int cmmdc(int a, int b);
  6.  
  7. int main()
  8. {
  9. int n, x, y, z, d;
  10. bool ok = true;
  11. bool ok2 = false;
  12. cin >> n;
  13. if (n < 2)
  14. {
  15. cout << "DA";
  16. return 0;
  17. }
  18. if (n == 2)
  19. {
  20. cin >> x >> y;
  21. if ( abs(x - y) != 1 )
  22. cout << "DA";
  23. else
  24. cout << "NU";
  25. return 0;
  26. }
  27. cin >> x >> y >> z;
  28. if (x != y || y != z)
  29. ok2 = true;
  30. d = cmmdc( abs(x - y), abs(y - z) );
  31. if (d == 1)
  32. ok = false;
  33. for (int i = 4; i <= n && ok; i++)
  34. {
  35. y = z;
  36. cin >> z;
  37. if (y != z)
  38. ok2 = true;
  39. d = cmmdc(d, abs(y - z) );
  40. if (d == 1)
  41. ok = false;
  42. }
  43. if (ok && ok2)
  44. cout << "DA";
  45. else
  46. cout << "NU";
  47. }
  48.  
  49. int cmmdc(int a, int b)
  50. {
  51. if (a == 0) return b;
  52. if (b == 0) return a;
  53. int r;
  54. while ( b )
  55. {
  56. r = a % b;
  57. a = b;
  58. b = r;
  59. }
  60. return a;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement