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
4
0
 
Sample Output
0
1
 
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的更多相关文章

  1. Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用

    OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...

  2. iOS 多线程之GCD的使用

    在iOS开发中,遇到耗时操作,我们经常用到多线程技术.Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法,只需定义想要执行的任务,然后添加到适当的调度队列 ...

  3. 【swift】BlockOperation和GCD实用代码块

    //BlockOperation // // ViewController.swift import UIKit class ViewController: UIViewController { @I ...

  4. 修改版: 小伙,多线程(GCD)看我就够了,骗你没好处!

    多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提升整体处理性能.具有这种能力的系 ...

  5. GCD的相关函数使用

    GCD 是iOS多线程实现方案之一,非常常用 英文翻译过来就是伟大的中枢调度器,也有人戏称为是牛逼的中枢调度器 是苹果公司为多核的并行运算提出的解决方案 1.一次性函数 dispatch_once 顾 ...

  6. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...

  7. hdu2588 GCD (欧拉函数)

    GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知 ...

  8. BZOJ 2820: YY的GCD [莫比乌斯反演]【学习笔记】

    2820: YY的GCD Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1624  Solved: 853[Submit][Status][Discu ...

  9. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

  10. GCD总结

    //用block只有两种:同步执行/异步执行(参数1:队列;参数二:任务) dispatch_async(dispatch_get_global_queue(0, 0),^{ });//异步在新的线程 ...

随机推荐

  1. Java 中与(&)短路与(&&)以及 或(|)短路或(||)的关系

    一.逻辑运算符的使用 1)逻辑运算符的连接的是布尔表达式,要与位运算符做区分. 2)使用方法: public class Test {  public static void main(String[ ...

  2. hdu 2609 How many 最小表示法

    How many Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. PHP MYSQL 搜索周边坐标,并计算两个点之间的距离

    搜索附近地点,例如,坐标(39.91, 116.37)附近500米内的人,首先算出“给定坐标附近500米”这个范围的坐标范围. 虽然它是个圆,但我们可以先求出该圆的外接正方形,然后拿正方形的经纬度范围 ...

  4. C#中 计时器用法

    有时候我们会需要计算某段代码运行的时间比如一个sql查询,记录一段代码所花费的时间等等代码如下: System.Diagnostics.Stopwatch watch = new System.Dia ...

  5. HDU1423 LCIS

    1,先离散化,然后DP: 注意这个解法中,dp[i][j][k]代表a序列中前i个和b序列中前j个数结尾为k或小于k时的最大. 但是由于i是单增(一次1->n),而j反复变化(多次1->m ...

  6. Tarjan LCA

    强连通 迷宫城堡 Proving Equivalences Equivalent Sets Summer Holiday Intelligence System The King's Problem ...

  7. java web jsp原理图 ,静态包含,动态包含,out与response.getWrite()

    jsp原理图 ,静态包含,动态包含,out与response.getWrite() 

  8. 张高兴的 Xamarin.Android 学习笔记:(二)“Hello World”

    完成环境配置后开始第一个简单项目.打开 Visual Studio 新建一个 Xamarin.Android 项目 "HelloAndroid".(GitHub:https://g ...

  9. HTML5中表单中新增加元素

    新增input 内属性 1,required:若文本内容为空,阻止表单提交格式,写入单词即可 如:<input type="text" name="username ...

  10. vs2012建一个空解决方案添加以前老版本的Web项目调试弹出window安全

    解决方法:NTLM身份验证去掉就行.