A - 互质数的个数(一)
题意:有t次询问,每次询问给一个数n,求出其欧拉函数。( 1 <= t <= 100 1 <= n <= 1e10)
思路:这道题的n很大,用筛法求欧拉函数数组都开不了,再加上t很小,所以可以考虑使用直接的欧拉函数,板题。
#include<iostream>
using namespace std;
typedef long long ll;
ll k, num;
ll phi(ll x)
{
ll res = x;
for (ll i = 2; i <= x / i; i ++ )
if (x % i == 0)
{
res = res / i * (i - 1);
while (x % i == 0) x /= i;
}
if (x > 1) res = res / x * (x - 1);
return res;
}//欧拉函数板子
int main(){
ios :: sync_with_stdio( false );
cin.tie( NULL );
cin >> k;
while( k-- ){
cin >> num;
cout << phi( num ) << "\n";
}
return 0;
}
B - 互质数的个数(二)
题意: 题意:有t次询问,每次询问给一个数n,求出其欧拉函数。( 1 <= t <= 1e6 1 <= n <= 1e6)
思路:这道题和上面是一样的,只是说n小了很多,但是t也打了很多,