首页 > 代码库 > HDU 2824 The Euler function
HDU 2824 The Euler function
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2824
解题思路:
打表筛选出一段范围内的欧蓝函数
实现代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=3000001; int phi[N]; void init(){ for(int i=1;i<N;i++) phi[i]=i; for(int i=2;i<N;i++){ if(i==phi[i]) //此时i是素数 for(int j=i;j<N;j+=i) phi[j]=(phi[j]/i)*(i-1); //每一个j都有素因子i } } int main(){ int a,b; init(); while(cin>>a>>b){ long long res=0; for(int i=a;i<=b;i++) res+=phi[i]; cout<<res<<endl; } }
HDU 2824 The Euler function
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。