• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

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 }
View Code

 

posted @ 2013-10-30 14:29  HaibaraAi  阅读(115)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3