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

7
12
0

Sample Output

6
4

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long LL ;
int euler(int n){ //返回euler(n)
int res=n,a=n;
for(int i=2;i*i<=a;i++){
if(a%i==0){
res=res/i*(i-1);//先进行除法是为了防止中间数据的溢出
while(a%i==0) a/=i;
}
}
if(a>1) res=res/a*(a-1);
return res;
} int main (){
int x;
while(~scanf("%d",&x)&&x){
printf("%d\n",euler(x));
}
return 0;
}

Relatives的更多相关文章

  1. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  2. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  3. POJ 2407:Relatives(欧拉函数模板)

    Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accept ...

  4. Text Relatives II

    [Text Relatives II] When your app determines that the user has requested the edit menu—which could b ...

  5. Text Relatives

    [Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...

  6. God made relatives.Thank God we can choose our friends.

    God made relatives.Thank God we can choose our friends. 神决定了谁是你的亲戚, 幸运的是在选择朋友方面他给了你留了余地

  7. POJ 2021 Relative Relatives

    Relative Relatives Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3339   Accepted: 146 ...

  8. Relatives(容斥)

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15708   Accepted: 7966 Descri ...

  9. POJ 2407 Relatives 【欧拉函数】

    裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i ...

随机推荐

  1. ES6 基础版迭代器

    ES6中引入了generator function* get() { var result1 = yield c; var result2 = yield b; var result3 = yield ...

  2. Mobiscroll 3.0 官方同步版

    Mobiscroll 3.0 官方同步版发布了. Mobiscroll是一个用于触摸设备的日期和时间选择器,它的使用不会改变HTML5.PhoneGap以及混合应用的原生用户体验.作为一款jQuery ...

  3. In close() at SocketHttpClientConnection in Android

    In close() at SocketHttpClientConnection Error In Android. when i tried to acess network data on Mai ...

  4. Jmeter—1 安装

    1  Jmeter运行需要java环境.首先需要安装JDK. 图标是这样的:  2 下载apache-jmeter包. jmeter官网:http://jmeter.apache.org/ 3  解压 ...

  5. Java中的泛型

    1:泛型(掌握) (1)泛型概述 是一种把明确类型的工作推迟到创建对象或者调用方法的时候才去明确的特殊的类型. (2)格式: <数据类型> 注意:该数据类型只能是引用类型. (3)好处: ...

  6. 关于jsonp跨域过程中 cookie中的值一直为null的原因

    今天技术交流群里的小伙伴一直被一个问题而困扰,就是写入cookie里面的值 再次进行请求时 cookie 就为空了 他被问题纠结了一天  我也好奇了一天 终于在快下班的时候 他解决掉了 下面我来收一个 ...

  7. 获取su后执行的脚本的返回值

    错误的方式: # su - testuser -c "/tmp/test.sh; echo $?"Sun Microsystems Inc.   SunOS 5.10      G ...

  8. hasLayout与BFC的触发条件

    hasLayout与BFC是分别在IE和其他浏览器上的两个作用很相近的概念,在很多时候,我们需要触发它们去实现有些效果.例如清除浮动时需要触发hasLayout与BFC:很多自适应的两栏和三栏布局(两 ...

  9. solr导入数据库数据-tinyint数据转boolean

    solr在导入mysql数据库数据时,遇到一个问题:数据类型为tinyint的数据对应不到solr中的数据类型,因此就需要将tinyint转一下. 修改schema.xml文件,如下: 1.添加boo ...

  10. Startup key combinations for Intel-based Macs

    Learn about the startup key combinations you can use with Intel-based Macs. You can use the followin ...