目录
题意:你懂得。
析:一看这个题应该是欧拉phi函数,也就说欧拉phi函数是指求从 1 到 n 中与 n 互素的数的个数,这个题很明显是这个意思嘛,不多说了。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 32768 + 5; int phi[maxn+5]; void phi_table( int n){ memset (phi, 0, sizeof (phi)); 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(){ phi_table(maxn); int n, T; cin >> T; while (T--){ scanf ( "%d" , &n); printf ( "%d\n" , phi[n]); } return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步