首页 > 代码库 > NYOJ 333 mdd的烦恼&&NYOJ 291 LK的数学题
NYOJ 333 mdd的烦恼&&NYOJ 291 LK的数学题
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=291 http://acm.nyist.net/JudgeOnline/problem.php?pid=333
思路:欧拉函数的应用,详解见这里:http://blog.csdn.net/once_hnu/article/details/6302868 好文章
直接贴代码:
#include <iostream>#include <cstring>using namespace std;int euler(int x){ int res = x; int a = x; 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 main(){ int n; int res; while(cin>>n) { cout<<euler(n)<<endl; } return 0;}
NYOJ 333 mdd的烦恼&&NYOJ 291 LK的数学题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。