Become A HeroTime Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 287 Accepted Submission(s): 79 Problem Description Lemon wants to be a hero since he was a child. Recently he is reading a book called “Where Is Hero From” written by ZTY. After reading the book, Lemon sends a letter to ZTY. Soon he recieves a reply. Input First line contains an integer T(1 <= T <= 1000000) indicates the number of test case. Then T line follows, each line contains an integer n (1 <= n <= 2000000). Output For each data print one line, the Answer(n). Sample Input 1 1 Sample Output 0 |
题意 : 求 1 ~ n 中与 n 不互质的数的个数
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout << "------------" << endl
typedef long long ll;
const int maxn = 2e6 + 10;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1010;
int phi[maxn];
void Euler(){
phi[1] = 1;
for(int i = 2; i < maxn; i++){
phi[i] = i;
}
for(int i = 2; i < maxn; i++){
if(phi[i] == i){
for(int j = i; j < maxn; j += i){
phi[j] = phi[j] / i * (i - 1);
}
}
}
}
int main(){
Euler();
int t;
cin>>t;
while(t--){
int n;
scanf("%d",&n);
printf("%d\n",n - phi[n]);
}
return 0;
}