http://poj.org/problem?id=2407

                                         Relatives
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16652   Accepted: 8470

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

Source

 
思路:欧拉函数板子题,就是就给定数字的欧拉函数
 
 
#include <iostream>
using namespace std;
#define LL long long
LL Phi(LL x){ //按定义直接算
if(x == 1){
return 1;
}
LL ans = x;
for(int i = 2; i * i <= x; i++){
if(x % i == 0){
ans = ans / i * (i - 1);
while(x % i == 0){
x = x / i;
}
}
}
// cout << ans << " " << x << endl;
if(x >= 2)
ans = ans / x * (x - 1);
return ans;
} //bool visit[10001];
//int tot=0, pri[1000005], phi[1000005];
//LL Phi(LL n){ //线性筛选
// phi[1] = 1;
// for(int i = 2; i <= n; i++){
// if(!visit[i]){
// pri[++tot] = i;
// phi[i] = i - 1;
// }
// for(int j = 1, x; j <= tot && (x = i * pri[j]) <= n; j++){
// visit[x] = true;
// if(i % pri[j] == 0){ //不互质时
// phi[x] = phi[i] * pri[j];
// break;
// }
// else{
// phi[x] = phi[i] * phi[pri[j]];
// }
// }
// }
// return phi[n];
//} int main(){
LL x;
while(cin >> x && x){
cout << Phi(x) << endl;
}
return 0;
}

  

76-Relatives-欧拉函数的更多相关文章

  1. poj2407 Relatives 欧拉函数基本应用

    题意很简单 就是欧拉函数的定义: 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) .题目求的就是φ(n) 根据 通式:φ(x)=x*(1-1/p1)*(1-1/ ...

  2. POJ 2407 Relatives(欧拉函数)

    题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...

  3. POJ2407–Relatives(欧拉函数)

    题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> # ...

  4. POJ 2407 Relatives 欧拉函数题解

    版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

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

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

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

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

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

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

  8. POJ 2407 Relatives 【欧拉函数】

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

  9. POJ2407 Relatives(欧拉函数)

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

  10. 欧拉函数K - Relatives

    欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n). 特殊性质:当n为奇数时,φ(2n)=φ(n), φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..( ...

随机推荐

  1. (转)如何获得当前ListVIew包括下拉的所有数据?

    ListView listView = activity.getListView();获取的仅仅是当前屏幕显示的list,但是具有下拉信息,不在当前屏幕,但是下拉显示的数据无法或得到.谁知道如何获得当 ...

  2. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  3. new String(tmp,1,nlen,"UTF8")

    tmp是一个byte(字节)数组,如:['a','b','c'...],tmp[0]是去byte中的第一个,运算符&表示按位运算‘且’,就是前后值的二进制相同位有0取0,否则取1,如:2&am ...

  4. 兼顾FPGA和单片机

    当今,FPGA和单片机的应用非常广泛,在有FPGA知识的基础上,笔者认为可以把FPGA作为主要的学习目标,单片机作为辅助技能.其实二者是相互促进的.不管是FPGA还是单片机的开发其实都是基于较强的逻辑 ...

  5. AndroidUI 控件命名格式

    TextView ->txt EditText->edit Button ->btn

  6. kafka 常用命令

    Kafka 解压,进入kafka目录下的bin目录 启动zk nohup ./zookeeper-server-start.sh ../config/zookeeper.properties & ...

  7. 小程序scroll-view组件使用时,子元素虽设置样式display:inline-flex;whit-space:nowrap

    小程序scroll-view组件使用时,子元素虽设置样式display:inline-flex;whit-space:nowrap

  8. ApacheOFBiz的相关介绍以及使用总结(三)

    Ofbiz中还提供了一些基础性服务,可以直接用来使用,下面就简单介绍说明一下.   ofbiz邮件发送服务   ofbiz中提供发送邮件相关功能:sendMailFromScreen   contex ...

  9. lnmp环境应用实践

    LNMP 用户通过浏览器输入域名请求nginx web服务,如果请求时静态资源,则由nginx解析返回给用户:如果是动态请求(.php结尾),那么nginx就会把它通过FastCGI接口(生产常用方法 ...

  10. 什么是 MVC ?

    本篇博客打算简单介绍一下MVC是什么,为接下来MVC的学习做一下铺垫. MVC是一种架构设计模式,是一种设计理念.是为了达到分层设计的目的,从而使代码解耦,便于维护和代码的复用.MVC是3个单词的缩写 ...