SGU 102 Coprimes
|
102. Coprimes time limit per test: 0.5 sec. memory limit per test: 4096 KB
For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime if (and only if) their greatest common divisor is 1. (i.e. A and B are coprime iff gcd(A,B) = 1).
Input Input file contains integer N.
Output Write answer in output file.
Sample Input 9 Sample Output 6 |
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <cstdlib> 10 #include <iostream> 11 #include <algorithm> 12 using namespace std; 13 #define maxn 105 14 #define ll long long 15 #define INF 0x7fffffff 16 #define eps 1e-8 17 int gcd(int n, int m){ return m ? gcd(m,n%m):n; } 18 int n, m; 19 int main(){ 20 int cas = 1; 21 int t; 22 while (~scanf("%d",&n)){ 23 //if (n == 1){ printf("1\n"); }//continue; } 24 t = 0; 25 for (int i = 1; i <= n; i++) 26 if (gcd(i, n) == 1)t++; 27 printf("%d\n", t); 28 //printf("%d\n",euler(n) + 1); 29 } 30 return 0; 31 }
浙公网安备 33010602011771号