hdu1787 GCD Again
来源:互联网 发布:linux清理目录 编辑:程序博客网 时间:2024/05/09 11:16
题意:给一个数n,求小于n的数中,有多少个数与n的最大公约数大于1。
思路:欧拉函数。欧拉函数的意义是小于n的数中,有多少个数与n互质,正好是题目要求的对立面。
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <iomanip> #include <cstdlib> #include <string> #include <memory.h> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <ctype.h>#define ll long long #define max3(a,b,c) max(a,max(b,c)) using namespace std; int main(){int n;while(cin>>n){if(!n)break;int nn=n;int tmp=n;int m=sqrt(n+0.5);for(int i=2;i<=m;i++){if(n%i==0){tmp=tmp/i*(i-1);while(n%i==0)n/=i;}}if(n>1)tmp=tmp/n*(n-1);ll ans=nn-tmp-1;cout<<ans<<endl;}return 0;}
0 0
- hdu1787-GCD Again
- hdu1787-GCD Again
- hdu1787 GCD Again
- HDU1787 GCD Again
- HDU1787——GCD Again
- HDU1787 GCD Again(容斥原理)
- hdu1787 GCD Again(数论:欧拉函数)
- HDU1787 GCD Again【欧拉函数】
- [HDU1787]GCD Again(根n求phi)
- HDU1787 GCD again 欧拉公式 的运用
- hdu1787 GCD Again 欧拉函数在线算法 待补完
- hdu1787——GCD Again(欧拉函数入门)
- (hdu1787)GCD Again(欧拉函数)
- 欧拉函数:HDU1787-GCD Again(欧拉函数的模板)
- GCD Again
- GCD Again
- GCD Again
- GCD Again
- Apply Bug10010310 On Oracle RAC 10.2.0.5
- linux程序管理
- 淘宝整理
- MySql数据库的基本操作-修改表-添加/修改约束(默认值)
- CLIF 数据库 和 VIVID 数据库
- hdu1787 GCD Again
- Java知识点小结
- zz
- 二项分布期望和方差的公式推导
- Gas Station
- Cakephp: [MissingTableException] 错误信息 解决方法
- poj 2965 The Pilots Brothers' refrigerator(dfs 枚举 +打印路径)
- IOS 内存管理 案例篇 MBProgressHUD
- OVa OJ 488 - Triangle Wave