Advertisement
palmerstone

Untitled

Jul 19th, 2011
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #define EPS 1e-8
  7. #define pi 3.1415926535897932384626433832795028841971693993751
  8. #define N 2147483647
  9.  
  10. int GreatestCommonDivisor(int a, int b)
  11. {
  12. if (b == 0) return a;
  13. else GreatestCommonDivisor(b, (a % b));
  14. }
  15.  
  16. int main()
  17. {
  18. int i, t, n, m, r, x, z, a, b, c, d, count, flag, y, l, j, k, count2;
  19. double p, q, u, v, xx, yy, zz;
  20. int ar[50000];
  21.  
  22. ar[0] = 2, ar[1] = 3, ar[2] = 5, ar[3] = 7, ar[4] = 11;
  23. for (j = 5; j < 4800; j++)
  24. {
  25. l = j - 1;
  26.  
  27. for (k = ar[j - 1] + 2; ; k = k + 2)
  28. {
  29. if ( (k % 5 != 0) && (k % 3 != 0) && (k % 7 != 0) )
  30. {
  31. y = k / 2;
  32. for (a = 4; a < l; a++)
  33. {
  34. if (ar[a] > y)
  35. {
  36. a = l;
  37. break;
  38. }
  39. if (k % ar[a] == 0)
  40. {
  41. break;
  42. }
  43. else if (a > 215)
  44. {
  45. a = l;
  46. break;
  47. }
  48. }
  49. if (a == l)
  50. {
  51. ar[j] = k;
  52. break;
  53. }
  54. }
  55. }
  56. }
  57.  
  58. for (; ;)
  59. {
  60. if (scanf("%d", &n) == EOF ) break;
  61.  
  62. y = n, xx = n, x = n;
  63. count = 0, flag = 0;
  64. for (j = 0; j < 4800;)
  65. {
  66. if (ar[j] > x) break;
  67. if (x % ar[j] == 0)
  68. {
  69. if (flag == 0)
  70. {
  71. yy = 1.0 / ar[j];
  72. zz = 1.0 - yy;
  73. xx = xx * zz;
  74. flag = 1;
  75. count++;
  76. }
  77. x = x / ar[j];
  78. }
  79. else
  80. {
  81. flag = 0;
  82. j++;
  83. }
  84. }
  85. if (x != 1)
  86. {
  87. yy = 1.0 / x;
  88. zz = 1.0 - yy;
  89. xx = xx * zz;
  90. }
  91. xx = xx + count;
  92. printf("%0.0lf\n", xx);
  93. }
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement