hdu 1787 GCD Again (欧拉函数)
2024-10-09 20:42:30
GCD Again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2257 Accepted Submission(s): 908
Problem Description
Do you have spent some time to think and try to solve those unsolved problem after one ACM contest?
No? Oh, you must do this when you want to become a "Big Cattle".
Now you will find that this problem is so familiar:
The greatest common divisor GCD (a, b) of two positive integers a and b, sometimes written (a, b), is the largest divisor common to a and b. For example, (1, 2) =1, (12, 18) =6. (a, b) can be easily found by the Euclidean algorithm. Now I am considering a little more difficult problem:
Given an integer N, please count the number of the integers M (0<M<N) which satisfies (N,M)>1.
This is a simple version of problem “GCD” which you have done in a contest recently,so I name this problem “GCD Again”.If you cannot solve it still,please take a good think about your method of study.
Good Luck!
No? Oh, you must do this when you want to become a "Big Cattle".
Now you will find that this problem is so familiar:
The greatest common divisor GCD (a, b) of two positive integers a and b, sometimes written (a, b), is the largest divisor common to a and b. For example, (1, 2) =1, (12, 18) =6. (a, b) can be easily found by the Euclidean algorithm. Now I am considering a little more difficult problem:
Given an integer N, please count the number of the integers M (0<M<N) which satisfies (N,M)>1.
This is a simple version of problem “GCD” which you have done in a contest recently,so I name this problem “GCD Again”.If you cannot solve it still,please take a good think about your method of study.
Good Luck!
Input
Input contains multiple test cases. Each test case contains an integers N (1<N<100000000). A test case containing 0 terminates the input and this test case is not to be processed.
Output
For each integers N you should output the number of integers M in one line, and with one line of output for each line in input.
Sample Input
2
4
0
Sample Output
0
1
Author
lcy
Source
Recommend
模板题:
//0MS 200K 399 B G++
#include<stdio.h>
int euler(int n)
{
int ret=;
for(int i=;i*i<=n;i++){
if(n%i==){
n/=i;ret*=i-;
while(n%i==){
n/=i;ret*=i;
}
}
}
if(n>) ret*=n-;
return ret;
}
int main(void)
{
int n;
while(scanf("%d",&n),n)
{
printf("%d\n",n-euler(n)-);
}
return ;
}
最新文章
- div盒子中子元素(子元素可能是盒子, 图片) 中居中的三种方法
- 【AT91SAM3S】串口UART初始化及收发数据
- java1.7集合源码阅读:LinkedList
- Entity Framework 5.0基础系列
- lazyload.js详解
- canvas API ,通俗的canvas基础知识(六)
- 如何在视频处理控件TVideoGrabber中设置音频捕捉设备
- Linux系统环境变量及命令
- app配置智能硬件的解决方案
- 抓取&ldquo;矢量&rdquo;的实时交通流量数据
- 解决Github使用Fastly CDN而导致不能加载网页的方法
- python爬取煎蛋图片
- CAN控制器-配置过滤器
- Order&;Shipping Transactions Status Summary
- RIPng(第三组)
- 机器学习---文本特征提取之词袋模型(Machine Learning Text Feature Extraction Bag of Words)
- 二分搜索-HihoCoder1128
- Shell学习之Shell特性(一)
- ServiceBase.OnStart 方法
- ipv6问题