UVA 10820(p322)----Send a Table
2016-02-27 13:22
363 查看
#include<cstdio> #include<iostream> #include<cstring> using namespace std; const int N=50000; int phi[N+50],x; long long ans; void init() { 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() { init(); while(scanf("%d",&x)==1&&x) { //cout<<x<<endl; if(x==1)printf("1\n"); else { ans=1; for(int i=2;i<=x;i++) { // cout<<i<<endl; ans+=2*phi[i]; // cout<<phi[x]<<endl; } printf("%lld\n",ans); } } return 0; }
相关文章推荐
- js面向对象编程:if中能够使用那些作为推断条件呢?
- 关于C++编译时内链接和外链接
- 文献笔记:《Fitting a 3D Morphable Model to Edges: A Comparison Between Hard and Soft Correspondences》读后感~
- LeetCode 12. Integer to Roman & 13. Roman to Integer
- UVA 10791(p317)----Minimum Sum LCM
- 安装andriod studio时出现Internal error. Please report to https://code.google.com/p/an
- 穷举法破解 zebrone1.1
- 用于PHP的Gearman Worker管理工具GearmanManager
- 抽象形式的观察者模式以及观察者模式的使用介绍
- IOS缓存机制详解
- TreeMap详细用法及案例分析
- android popwindow和dialog的取舍
- 数据的存储结构与逻辑结构
- 一种C#生成符合Java规则的二进制文件方法
- object对象、伴生类与伴生对象与类的继承实战
- TreeMap的最基本用法
- cordova技术集(一)Hello,cordova! 如何创建cordova项目。
- Scanner扫面器是否要关闭
- VAssistX使用技巧
- Hadoop的JobControl设计及用法