102. Coprimes time limit per test: 0.25 sec. 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 |
//
// main.cpp
// SGU102
//
// Created by luras on 15/12/25.
// Copyright (c) 2015年 luras. All rights reserved.
//
#define ms(x, y) memset(x, y, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(x))
#define ls o << 1
#define rs o << 1 | 1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
template <class T> inline void gmax(T &a, T b){if(b > a) a = b;}
template <class T> inline void gmin(T &a, T b){if(b < a) a = b;}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
typedef long long LL;
void fre()
{
freopen("/Users/luras/Desktop/in.txt", "r", stdin);
freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
int euler(int n)
{
int res = n;
int a = n;
for(int i = 2; i * i <= a; i ++){
if(a % i == 0){
res = res / i * (i - 1);
while(a % i == 0) a /= i;
}
}
if(a > 1) res = res / a * (a - 1);
return res;
}
int n;
int main()
{
while(~ scanf("%d", &n)){
printf("%d\n", euler(n));
}
return 0;
}
/*
题意:
类型:
欧拉函数||暴力
分析:
优化:
trick:
数据:
Sample Input
Sample Output
*/