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 > , y > , z >  such that a = xy and b = xz.

Input

There are several test cases. For each test case, standard input contains a line with n <= ,,,. A line containing  follows the last case.

Output

For each test case there should be single line of output answering the question posed above.

Sample Input


Sample Output

Source

 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define ll long long
ll eular(ll n){
ll ans=;
for(ll i=;i*i<=n;i++){
if(n%i==){
ans*=i-,n/=i;
while(n%i==){
ans*=i;
n/=i;
}
}
}
if(n>) ans*=n-;
return ans;
}
int main()
{
ll n;
while(scanf("%I64d",&n)==){
if(n==) break;
ll ans=eular(n);
printf("%I64d\n",ans);
}
return ;
}

poj 2407 Relatives(简单欧拉函数)的更多相关文章

  1. POJ 2407 Relatives(欧拉函数)

    http://poj.org/problem?id=2407 题意: 给出一个n,求小于等于的n的数中与n互质的数有几个. 思路: 欧拉函数的作用就是用来求这个的. #include<iostr ...

  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 【欧拉函数】

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

  4. POJ 2407 Relatives (欧拉函数)

    题目链接 Description Given n, a positive integer, how many positive integers less than n are relatively ...

  5. POJ 2407 Relatives【欧拉函数】

    <题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...

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

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

  7. poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)

    http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...

  8. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

  9. POJ2407 Relatives(欧拉函数)

    题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...

  10. (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))

    /* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...

随机推荐

  1. 【爬虫问题】爬取tv.sohu.com的页面, 提取视频相关信息

    尝试解决下面的问题 问题: 爬取tv.sohu.com的页面, 提取视频相关信息,不可用爬虫框架完成 何为视频i关信息?属性有哪些? 需求: 做到最大可能的页面覆盖率 *使用httpClient 模拟 ...

  2. SqlServer 笔记

    问题一:这标红色的符号 取掉 一直没有见过标红色的符号,尝试把这些符号粘贴出来到 notepad 发现它是乱码,尝试将它粘贴到sql查询分析器里,发现它显示空白.对于这种数据,一直想着找到这个acsi ...

  3. windows下php+apache+mysql环境搭建

    在Windows 7下进行PHP环境搭建,首先需要下载PHP代码包和Apache与Mysql的安装软件包. PHP版本:php-5.3.2-Win32-VC6-x86,VC9是专门为IIS定制的,VC ...

  4. 挂载(mount)深入理解

    首先引用一句 wiki 上的定义来开篇: Mounting takes place before a computer can use any kind of storage device (such ...

  5. Linux文件的查找

    一直以来,总是记不住文件的查找命令,今天记在博客里,希望可以记得更牢! 1.脚本文件名的查询 which命令(寻找执行文件) #which ifconfig 2.文件名的查找 whereis 命令 # ...

  6. LDAP错误代码221

    ---------------------------命令方式启动失败报错-------------------------------[root@rusky bin]# ./dsadm start ...

  7. 浅述Oracle分布式事务概念

    着系统的复杂性不断增加,我们所面对的分布式系统渐渐增加.分布式文件系统.分布式消息队列系统等等层出不穷,在一些行业特别是互联网行业应用广泛.分布式数据库也是目前使用比较常用的分布式系统之一. 简单来说 ...

  8. asp.net "callback" 和 "postback" 的区别.

    下图解释了基于 asp.net的 "postback" 和 "callback"的生命周期: Postback 是在将 整个页面的数据 从 client 提交到 ...

  9. HTML写的第一个邮箱登陆界面

    自己动手去写才会有收获,宁可模仿也不要全部复制粘贴 不说了,直接上代码.CSS有注释,适合新手. <!doctype html> <html> <head> < ...

  10. html+css布局小练习w3cfuns

    虽然花了很长时间,但是也知道了不少,这次也不像以前了,不知道怎么下手,虽然是照着图片做,不过也做出来了图片来自w3cfuns:网站图片url  看了w3cfuns的两天驾驭DIV+CSS 这个网站对新 ...