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. 工业标准接口OPC Server

    工业标准接口OPC  Server OPC Server服务器软件,简称OPCServer,是针对企业生产过程中所涉及到的各种DCS.PLC.组态软件.电力综合自动化等控制系统.测量系统.其它辅助生产 ...

  2. php 操作提示框

    /** * 跳转 * @param type $msg * @param type $url */ protected function jump($msg, $url) { $html = < ...

  3. postman参数化的方法

    1.准备csv格式的文件(注意第一行是是引用参数的名称) 2.编写请求,应用变量参数,并且设置断言 引用变量参数 3.把这个请求的文件夹runner一下批量执行 4.把第一步变量的csv文件在runn ...

  4. app的apk 安装的方法--adb--命令安装 (含把apk放某个文件夹,每次启动自己安装)

    adb安装 1.在app自动化之前,首先手机上有要被测试的app,如何把电脑本地上的app安装到手机上呢?可以在运行自动化代码前,在cmd输入adb指令,把电脑app安装到手机上 adb instal ...

  5. 编写hibernateDao,使dao层都实现hibernateDao

    package com.wiseweb.core.dao; import java.io.Serializable; import java.util.ArrayList; import java.u ...

  6. html5的canvas方法的总结

    canvas的方法 save()保存当前环境的状态 restore() 返回之前保存过的路径状态和属性 createEvent() getContext()返回一个对象,指出访问绘图功能必要的API ...

  7. JAVA中的IO流介绍(2)

    一.流的概念 流(stream)的概念源于UNIX中管道(pipe)的概念.在UNIX中,管道是一条不间断的字节流,用来实现程序或进程间的通信,或读写外围设备.外部文件等. 一个流,必有源端和目的端, ...

  8. Linux 下 实现 锐捷验证的方式

    准备工作:下载mentohust并安装 步骤: 1.打开终端,输入sudo mentohust 2.配置相关参数,网卡选第一个,用户名密码自己输入,类型选锐捷私有,DHCP选认证前.完成后回车即可通过 ...

  9. NIO编程介绍

    代码: package bhz.nio; import java.io.IOException; import java.net.InetSocketAddress; import java.nio. ...

  10. 4、数据类型二:Lists

    1.关于list的组织形式 列表数据类型(Lists)可以存储一个有序的字符串列表,常用的操作时向列表两段添加元素,或者获取列表的某一个片段.列表类型的底层实现是一个双向链表(double linke ...