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. apache启动时80端口占用的解决方法

    问题: (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in ...

  2. FileWriter和FileReader简单使用

    FileWriter和FileReader使用 package com.main.test; import java.io.FileNotFoundException; import java.io. ...

  3. 黑马程序员——【Java基础】——GUI(图形用户界面)

    ---------- android培训.java培训.期待与您交流! ---------- 一.概述 1.GUI(GraphicalUser Interface):又称图形用户界面,是计算机用户与计 ...

  4. bigworld源码分析(5)——BaseApp分析

    BaseApp负载部分,核心代码缺失...网上的源码中都找不到,暂时没办法分析其核心内容,很遗憾,继续寻找吧,等找到了,再继续自己的分析.

  5. zookeeper命令行(zkCli.sh&zkServer.sh)使用及四字命令

    zookeeper提供了很多方便的功能,方便我们查看服务器的状态,增加,修改,删除数据(入口是zkServer.sh和zkCli.sh). 还提供了一系列四字命令,方便我们跟服务器进行各种交互,来确认 ...

  6. Opencv结构与内容

    一.Opencv的结构分类: cxcore.cv.ML(Machine Learning).HighGUI.cvcam.cvaux 二.常见结构的内容与算法: 1.cxcore库(基本结构和算法.XM ...

  7. zoj3551 Bloodsucker ——概率DP

    Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4530 A[i]数组表示当吸血鬼有 I 个的时候,还需要的天数.可以 ...

  8. AJAX部分---php-jquery-ajax;

    AJAX的应用场景 1.异步搜索过滤内容数据 2.表单异步验证 3.异步加载页面“更多”数据 4.异步处理登录 5.异步处理用户名是否注册 AJAX的主要特点 1.在不刷新页面的情况下,与服务器进行异 ...

  9. kuangbin_SegTree E (HDU 1698)

    POJ服务器炸了 还没好呢 然后就只能跳掉一些题目了 这题也是成段更新模板题 本来lazy标记不是很明白 后来学长上课讲了一下就知道原理了 回去看看代码很容易就理解了 #include <cst ...

  10. Python 100道题深入理解

    # -*- coding: utf-8 -*-# 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?# 程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所 ...