博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10280(欧拉函数)
阅读量:6953 次
发布时间:2019-06-27

本文共 1384 字,大约阅读时间需要 4 分钟。

题意:找n以内有多少对互质的数。

思路:欧拉函数预处理一下,然后答案等于(∑Euler(i)-1)*2 + 1  i从1到n。

代码如下:

1 /************************************************** 2  * Author     : xiaohao Z 3  * Blog     : http://www.cnblogs.com/shu-xiaohao/ 4  * Last modified : 2014-03-28 18:19 5  * Filename     : uva_10820.cpp 6  * Description     :  7  * ************************************************/ 8  9 #include 
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #define MP(a, b) make_pair(a, b)21 #define PB(a) push_back(a)22 23 using namespace std;24 typedef long long ll;25 typedef pair
pii;26 typedef pair
puu;27 typedef pair
pid;28 typedef pair
pli;29 typedef pair
pil;30 31 const int INF = 0x3f3f3f3f;32 const double eps = 1E-6;33 const int LEN = 500010;34 int dp[LEN];35 36 int Euler(int n)37 {38 int ans = n;39 for(int i=2; i<=sqrt(n); i++){40 if(n%i == 0){41 ans = ans / i * (i-1);42 while(n%i == 0) n /= i;43 }44 } 45 if(n > 1) ans = ans / n * (n-1);46 return ans;47 }48 49 int main()50 {51 // freopen("in.txt", "r", stdin);52 53 int n;54 dp[0] = 0;55 for(int i=1; i
> n){58 if(!n) break;59 cout << (dp[n]-1) * 2 + 1 << endl;60 }61 return 0;62 }
View Code

 

转载于:https://www.cnblogs.com/shu-xiaohao/p/3631278.html

你可能感兴趣的文章
C语言基础(一)
查看>>
python处理xml中非法字符的一种思路
查看>>
itextSharp 附pdf文件解析
查看>>
solr6.0.0 + tomcat8 配置问题
查看>>
[leetcode-303-Range Sum Query - Immutable]
查看>>
LinkButton(按钮)
查看>>
leetcode Largest Rectangle in Histogram 单调栈
查看>>
Word Break II
查看>>
驱动lx4f120h,头文件配置,没有完全吃透,望指点
查看>>
caffe linux下面的调试mnist遇到的问题
查看>>
IOS的Application以及IOS目录的介绍
查看>>
SDN第六次上机作业
查看>>
虚拟Linux系统使用Windows系统oracle数据库
查看>>
javascript之奇淫技巧
查看>>
python 使用函数参数注解
查看>>
Redis五大数据类型以及操作---散列表
查看>>
重载类型转换操作符(overload conversion operator)
查看>>
bootstrap学习(二)页面
查看>>
C++ sizeof操作符的用法和strlen函数的区别
查看>>
文件的续写
查看>>