GCD Again
GCD Again |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 193 Accepted Submission(s): 112 |
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!
|
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 |
Sample Output
0 |
Author
lcy
|
Source
2007省赛集训队练习赛(10)_以此感谢DOOMIII
|
Recommend
lcy
|
/*
题意:给出你一个数n,然后让你求出比n小的,并且不与n互质的数的个数 初步思路:欧拉函数,用n减去欧拉函数-1
*/
#include<bits/stdc++.h>
using namespace std;
/**************************欧拉函数模板*****************************/
int euler(int n){
int cur=n,i;
for(i=;i*i<=n;i++){
/*
怎么样保证每一个能被n整除的数都是素因子呐,比当前i大的数,肯定能找到一个素数,相乘等于n
那么只需要每找到一个素数就把n中所有能和这个素数相乘等于n的数全部去除掉,那么这样就能满足
要求了。
*/
if(n%i==){
cur=cur-cur/i;
while(n%i==)
n/=i;
}
}
if(n>) cur=cur-cur/n;
return cur;
}
/**************************欧拉函数模板*****************************/
int n;
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF&&n){
printf("%d\n",n-euler(n)-);
}
return ;
}
GCD Again的更多相关文章
- Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用
OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...
- iOS 多线程之GCD的使用
在iOS开发中,遇到耗时操作,我们经常用到多线程技术.Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法,只需定义想要执行的任务,然后添加到适当的调度队列 ...
- 【swift】BlockOperation和GCD实用代码块
//BlockOperation // // ViewController.swift import UIKit class ViewController: UIViewController { @I ...
- 修改版: 小伙,多线程(GCD)看我就够了,骗你没好处!
多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提升整体处理性能.具有这种能力的系 ...
- GCD的相关函数使用
GCD 是iOS多线程实现方案之一,非常常用 英文翻译过来就是伟大的中枢调度器,也有人戏称为是牛逼的中枢调度器 是苹果公司为多核的并行运算提出的解决方案 1.一次性函数 dispatch_once 顾 ...
- hdu1695 GCD(莫比乌斯反演)
题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- BZOJ 2820: YY的GCD [莫比乌斯反演]【学习笔记】
2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1624 Solved: 853[Submit][Status][Discu ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- GCD总结
//用block只有两种:同步执行/异步执行(参数1:队列;参数二:任务) dispatch_async(dispatch_get_global_queue(0, 0),^{ });//异步在新的线程 ...
随机推荐
- 插入排序-python实现
def insert_sort(arr): for j in range(1,len(arr)): #从list第二个元素开始 key=arr[j] ...
- 【京东账户】——Mysql/PHP/Ajax爬坑之产品列表显示
一.引言 实现京东的账户项目,功能模块之一,产品列表显示.要用到的是Apach环境,Mysql.PHP以及Ajax. 二.依据功能创建库.表.记录 创建库:jd 创建表:产品表 添加多条记录 /**产 ...
- 【Python练习1】统计一串字符中英文字母、空格、数字和其他字符的个数
练习思路: 1.输入一串字符 2.筛选出字符中的英文字母并统计 3.筛选出字符中的空格并统计 4.筛选出字符中的数字并统计 5.筛选出字符中的其他字符并统计 代码实现: def msg(s): abc ...
- LPCTSTR LPCWSTR LPCSTR 含义
#ifdef UNICODE#define LPCTSTR LPCWSTR#else#define LPCTSTR LPCSTR#endif LPCTSTR A 32-bit pointer ...
- jQuery ajax的提交
1.利用jQuery中的aja提交数据,首先引入jQuery中的文件 2.jquery.form.js下载地址:http://vdisk.weibo.com/s/thY_x31gX0M-p?categ ...
- Asp.Net MVC4 系列-- 进阶篇之路由(1)
创建一个路由 打开 RouteConfig.cs ,发现已经创建了一个默认路由 : routes.MapRoute( name:"Default", url:"{con ...
- JAVA继承:编译与运行的关系(编译看左边,运行看右边)
"成员变量,静态方法看左边:非静态方法:编译看左边,运行看右边." 意思是:当父类变量引用子类对象时(Fu f = new Zi();),在这个引用变量f指向的对象中,他的成员变量 ...
- win10 uwp 关联文件
有时候应用需要打开后缀名为x的文件,那么如何从文件打开应用? 首先,需要打开 Package.appxmanifest 添加一个功能,需要添加最少有名称,文件类型. 上面的图就是我添加jpg 的方法, ...
- Struts2 06--系统拦截器防止数据重复提交
一.拦截器简要概述 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作.拦截是AOP的一种实现策略. 在W ...
- UVa10723 - Cyborg Genes
这题我能想到的解决方法是: 最优解的长度好找,两串的长度和-LCS: 根据anslen,枚举出解的数目...但想不出简单有效的枚举方法,这种做法可能超时 网上看大神的博客后,发现大家都用的此方法: 最 ...