TOJ 1395.Relatives
来源:互联网 发布:香港域名注册商 编辑:程序博客网 时间:2024/04/30 03:40
题目链接 : http://acm.tju.edu.cn/toj/showp1395.html
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.
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.For each test case there should be single line of output answering the question posed above.
Sample Input
7
12
0
Sample Output6
4
知道欧拉函数的话很容易就做出来了,说白了就是求欧拉函数的值。直接上代码,不知道欧拉函数可以去看这篇:http://blog.csdn.net/muyujinxi/article/details/52164510
#include <stdio.h>using namespace std;int euler(int n){ int sum=n; for(int i=2;i*i<=n;i++){ if(n%i==0){ sum=sum-sum/i; while(n%i==0) n/=i; } } if(n>1) sum=sum-sum/n; return sum;}int main(){ int n; while(scanf("%d",&n) && n) printf("%d\n",euler(n));}
0 0
- TOJ 1395.Relatives
- Relatives
- Relatives
- Relatives
- JOJ1874:Relatives
- pku2407 Relatives
- poj2407-Relatives
- poj2407 Relatives
- [POJ2407] Relatives
- POJ2407 Relatives
- Relatives【POJ2407】
- poj2407 Relatives
- POJ2407 Relatives
- [POJ2407]Relatives
- FZU 1012 Relatives
- Relatives 【欧拉函数】
- POJ2021 Relative Relatives
- POJ 2021 Relative Relatives
- 关于共交车对黄色座位的思考
- JAVA字符串转日期或日期转字符串
- 这个夏天的我
- Neither BindingResult nor plain target object for bean name 'command' available as request attribute
- OpenCV读取AVI帧至Mat
- TOJ 1395.Relatives
- struts2标签<s:property value=""/> ognl和el
- DataGridView取消默认选中行
- js获取windows操作系统版本
- Storm 单机和分布式安装
- 爱上C++的各种流
- 今天的精彩看点,你错过了吗?
- 安全工具及利用
- Java自定义注解详解