博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2407:Relatives(欧拉函数模板)
阅读量:7197 次
发布时间:2019-06-29

本文共 1535 字,大约阅读时间需要 5 分钟。

                                             Relatives

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16186   Accepted: 8208

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

7120

Sample Output

64

Source

 

 

欧拉函数模板题

AC代码

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define ms(a) memset(a,0,sizeof(a))#define pi acos(-1.0)#define INF 0x3f3f3f3fconst double E=exp(1);using namespace std;const int maxn=1e6+10;int a[maxn];int b[maxn];//欧拉函数公式://φ(N)=N*(1-1/P1)*(1-1/P2)*...*(1-1/Pn).int main(int argc, char const *argv[]){ int n; while(cin>>n&&n) { ms(b); ll ans=n; int vis=n; for(int i=2;i*i<=vis;i++) { if(vis%i==0) { ans=ans/i*(i-1); while(vis%i==0) { vis/=i; } } } if(vis>1) ans=ans/vis*(vis-1); cout<
<
1)res =res/a*(a-1);//res -= res/a;// return res;// } // ******************第二种打表求解****************// #define Max 1000001// int euler[Max];// void Euler()// {// euler[1]=1;// for(int i=2;i

 

转载于:https://www.cnblogs.com/Friends-A/p/10324444.html

你可能感兴趣的文章
hdu 1698 Just a Hook
查看>>
搭建基于ubuntu14.04麒麟的hadoop单机测试环境
查看>>
基于Python的数据分析(1):配置安装环境
查看>>
常用术语
查看>>
标准时间格式("%Y-%m-%dT%H:%M:%S")转化(基于python 3.6)
查看>>
Java基础
查看>>
【转】jmeter学习笔记——一个简单的接口测试
查看>>
C++ constexpr lambda
查看>>
二叉搜索树
查看>>
mysql workbench建模导出sql文件创建数据库注释乱码
查看>>
Javascript之BOM与DOM讲解
查看>>
四则运算3
查看>>
快速学习javaSE基础3-java必须了解的基本语法1(熟记)
查看>>
树莓派 离线安装 apt-get offline
查看>>
网络对抗技术实验二 网络嗅探与欺骗
查看>>
磁盘IO概念及优化入门知识
查看>>
ListView解析
查看>>
Cubieboard2裸机开发之(二)板载LED交替闪烁
查看>>
JDBC自定义工具类
查看>>
Two Sum II - Input array is sorted
查看>>