Relatives+水题+欧拉函数+素数打表的基本应用+poj
来源:互联网 发布:卧龙进阶数据 编辑:程序博客网 时间:2024/05/17 08:27
Relatives
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11122 Accepted: 5383
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
解决方案:水题,没什么好说的。
code:
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#define MMAX 100000using namespace std;vector<int >prime;bool vis[MMAX];void init_prime(){ memset(vis,false,sizeof(vis)); prime.clear(); prime.push_back(2); for(int i=3;i<MMAX;i+=2){ if(!vis[i]){ prime.push_back(i); for(int j=i+i;j<MMAX;j+=i) vis[j]=true; } }}int euler(int x){ long long res=x; int len=prime.size(); for(int i=0;i<len;i++){ if(x%prime[i]==0){ res=res/prime[i]*(prime[i]-1); while(x%prime[i]==0) x/=prime[i]; } } if(x>1) res=res/x*(x-1); return res;}int main(){ long long n; init_prime(); while(~scanf("%lld",&n)&&n){ printf("%d\n",euler(n)); } return 0;}
0 0
- Relatives+水题+欧拉函数+素数打表的基本应用+poj
- poj2407 Relatives 欧拉函数基本应用
- POJ 2407 Relatives(欧拉函数的应用)
- 欧拉函数的应用&&Relatives
- POJ-20407Relatives/NYOJ-333mdd的烦恼,欧拉函数简单应用,模板A
- POJ 2407 Relatives && UVA 10299 Relatives(欧拉函数)
- 【POJ 2407】Relatives(欧拉函数-水题)
- POJ 2407 Relatives 欧拉函数
- POJ 2407 Relatives 欧拉函数
- POJ 2047 Relatives 欧拉函数
- poj 2407 Relatives(欧拉函数)
- poj-Relatives(欧拉函数)
- POJ 2407 Relatives 欧拉函数题解
- poj 2407Relatives(数论:欧拉函数)
- [POJ 2407]Relatives(欧拉函数)
- POJ 2407 Relatives (欧拉函数)
- POJ 2407 : Relatives - 欧拉函数
- POJ 2407 Relatives(欧拉函数)
- 数据库设计
- 替换URL中指定参数的值
- theano 训练样本制作(二)
- POJ 2151--Check the difficulty of problem
- 读《百度基础架构技术发展之路》有感 .
- Relatives+水题+欧拉函数+素数打表的基本应用+poj
- Android快捷开关实现
- 比较时间日期
- 不声明新变量交换两值
- coach factory online Asos bags another M veteran in Ian Dyson
- VS 与 SQLite数据库 连接
- true religion wholesale Adventures made accessible
- vim使用(一):基本命令
- 关于startActivityForResult你可能不知道的