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. GCD与block

    GCD技术多线程编程的三个技术  NSThread NSOperation GCD1.GCD(Grand central Dispatch:宏大的中央调度)        1) 是用纯C语言实现的.提 ...

  2. UISlider

    UISlider是iOS中的滑块控件 通常⽤于控制视频播放进度,控制⾳量等. 它继承于UIControl,滑块提供了⼀系列连续的值,滑块停 在不同的位置,获取到滑块上的值也不同.   minimumV ...

  3. WP8.1 Study18:动态磁贴

    一.前言 动态磁贴在WindowsPhone8.1和Windows8.1都是其特色,有人喜欢有人讨厌,不过我觉得还是挺好的,可以让使用者很快知道App内的内容和吸引使用者打开App.下面来学习下怎样添 ...

  4. HTML5新增video标签及对应属性、API详解

    知识说明: 比不上很牛的前端开发人员,但自始至终明白“万丈高楼平地起”,基础最重要,初学HTML5,稳固基础第一步,把最基本的整理下来,留下自己学习的痕迹.HTML5新增的video标签,将其属性以及 ...

  5. 动态获取Android权限

    @TargetApi(23)private void showPhotoDialog() { if (dialog != null && dialog.isShowing()) { d ...

  6. WAMP环境启动失败处理办法

    点击控制面板->系统与安全->管理工具->查看事件日志->windows日志->应用程序 查看错误日志,查找错误并解决

  7. 运用Fluxion高效破解WiFi密码

    Fluxion是一个无线破解工具,这个工具有点像是Linset的翻版.但是与Linset比较起来,它有着更多有趣的功能.目前这个工具在Kali Linux上可以完美运行. 工作原理 1.扫描能够接收到 ...

  8. 安装Adobe Flash Player

    安装Adobe Flash Player:         Adobe Flash Player的安装比较容易,只要将对应的文档复制到正确的的位置即可,具体的操作 如下:         (1) 将l ...

  9. OpenSSL - 网络安全之数据加密和数字证书

    功能应用: 消息摘要,给文件或数据生成消息摘要,消息摘要只能校验数据的完整性,如SHA.MD5 数据加密和解密:对数据进行加密解密,OpenSSL实现了所有加密算法 数字证书:可以通过命令行或代码生成 ...

  10. watir学习系列--Watir API介绍

    文本框:          <INPUT id="email" name="_fmu.u._0.e" value="" />   ...