您的位置:首页 > 其它

SGU 102 —— 欧拉函数

2013-12-11 16:31 274 查看


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
直接欧拉函数打表即可!
/*
ID: XMzhou
LANG: C++
TASK: ariprog
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cassert>
using namespace std;
///#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 10000 + 50;
const int MAXS = 10000 + 50;
const int sigma_size = 26;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
const int inf = 1 << 30;
#define eps 1e-10
const long long MOD = 1000000000 + 7;
const int mod = 10007;
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
typedef pair<int , int> pii;
typedef vector<int> vec;
typedef vector<vec> mat;

#define Bug(s) cout << "s = " << s << endl;
///#pragma comment(linker, "/STACK:102400000,102400000")
int phi[MAXN];
void phi_table(int n)
{
for(int i = 2 ; i <= n ; i ++)phi[i] = 0;
phi[1] = 1;
for(int i = 2 ; i <= n ; i++)if(!phi[i])
{
for(int j = i ; j <= n ; j += i)
{
if(!phi[j])phi[j] = j;
phi[j] = phi[j] / i * (i - 1);
}
}
}

int main()
{
//ios::sync_with_stdio(false);
#ifdef Online_Judge
freopen("ariprog.in","r",stdin);
freopen("ariprog.out","w",stdout);
#endif // Online_Judge
phi_table(10000);
int n;
while(~scanf("%d" , &n))
{
printf("%d\n" , phi
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM 数论