Relatives(poj2407)(求大数的欧拉函数模板题)
来源:互联网 发布:我的世界0.15js家具 编辑:程序博客网 时间:2024/05/17 01:37
Link:http://poj.org/problem?id=2407
Relatives
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12582 Accepted: 6144
Description
Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.
Input
There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.
Output
For each test case there should be single line of output answering the question posed above.
Sample Input
7120
Sample Output
64
Source
Waterloo local 2002.07.01
AC code:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<queue>#include<map>#include<stack>#include<vector>#define LL long long#define MAXN 100010using namespace std;//直接求解欧拉函数int euler(int n){ //返回euler(n) int res=n,a=n; 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;while(~scanf("%d",&n)){if(n==0)break;printf("%d\n",euler(n)); } return 0;}
0 0
- Relatives(poj2407)(求大数的欧拉函数模板题)
- 欧拉函数 模板题 POJ2407 Relatives
- POJ2407-Relatives(欧拉函数裸题)
- POJ2407 Relatives 【欧拉函数模板】
- POJ2407---Relatives(求单个数的欧拉函数)
- 【欧拉函数】 poj2407 Relatives(裸欧拉函数)
- POJ2407:Relatives(欧拉函数)
- POJ2407 Relatives(欧拉函数)
- poj2407 Relatives 欧拉函数基本应用
- POJ-2407-Relatives(欧拉函数模板题)
- poj2407欧拉函数模板
- poj 2407 Relatives(欧拉函数模板)
- poj2407(欧拉函数-套模板)
- POJ 2407 Relatives && UVA 10299 Relatives(欧拉函数)
- (欧拉函数) Relatives (P2407)
- poj 2407 Relatives(欧拉函数)
- poj-Relatives(欧拉函数)
- POJ 2407 Relatives(欧拉函数)
- struct tm 的应用
- 【转】Google如何管理20亿行代码
- Item 31:最小化文件之间的编译依赖 Effective C++笔记
- 由浅入深--继续Tableau
- POJ-1595
- Relatives(poj2407)(求大数的欧拉函数模板题)
- app store游戏全被下架,原因竟然是,最惨淡的一天
- 学习之路之自定义内容提供者
- Android 动画效果(二):四种基础动画的 **动态设置、动画监听、组合动画
- sql 查询重复数据和清除重复数据
- OC学习篇之---KVC和KVO操作
- UITextField
- 【MDCC技术大咖秀】Android内存优化之OOM
- Node.js中的文件系统(FS)