首页 > 代码库 > sgu 102 Coprimes
sgu 102 Coprimes
太水了, 我都不忍心发题解, 但毕竟是sgu上一道题, 我试试能不能一直这么写下去,就是求phi,上代码
#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #define N 10010 using namespace std; int get_phi(int n) { int m = sqrt(n+0.5); int ans = n; for (int i = 2; i <= m; ++i) if (n % i == 0) { ans = ans / i * (i-1); while (n % i == 0) n /= i; } if (n > 1) ans = ans / n * (n-1); return ans; } int main() { int n; scanf("%d", &n); printf("%d\n", get_phi(n)); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。