POJ-20407Relatives/NYOJ-333mdd的烦恼,欧拉函数简单应用,模板A
Time Limit: 1000MS | Memory Limit: 65536K | |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |

void fun(int x)
{
int ans=x,n=x;
for(int i=2;i*i<=n;i++)
if(n%i==0)
{
ans-=ans/i;就相当于a*(1-1/p);
while(n%i==0)
n/=i;
}
if(n>1) ans-=ans/n;
printf("%d\n",ans);
}//感觉这个函数效率还是蛮高的;
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
fun(n);
}
return 0;
}
nyoj mdd的烦恼
<-
long 便可以了;
void fun(long long x)
{
long long ans=x,n=x;
for(long long i=2; i*i<=n; i++)
if(n%i==0)
{
ans-=ans/i;
while(n%i==0)
n/=i;
}
if(n>1) ans-=ans/n;
printf("%lld\n",ans);
}
int main()
{
long long n;
while(~scanf("%lld",&n)&&n)
{
fun(n);
}
return 0;
}//这里就不再赘述了;
const int N=1000000+10;
int euler[N];
void Init( )
{
memset(euler,0,sizeof(euler));
euler[1]=1;//初始化1,请注意根据实际情况做出更改;
for(int i=2; i<N; i++)
if(!euler[i])
{
for(int j=i; j<N; j+=i)//类似于素数筛法打表;
{
if(!euler[j])
euler[j]=j;
euler[j]-=euler[j]/i;//关键;
}
}
}
int main()
{
int n;
Init();
while(~scanf("%d",&n)&&n)
{
printf("%d\n",euler[n]);
}
return 0;
}
POJ-20407Relatives/NYOJ-333mdd的烦恼,欧拉函数简单应用,模板A的更多相关文章
- poj 2154 Color(polya计数 + 欧拉函数优化)
http://poj.org/problem?id=2154 大致题意:由n个珠子,n种颜色,组成一个项链.要求不同的项链数目.旋转后一样的属于同一种.结果模p. n个珠子应该有n种旋转置换.每种置换 ...
- POJ 2773 Happy 2006【GCD/欧拉函数】
根据欧几里德算法,gcd(a,b)=gcd(a+b*t,b) 如果a和b互质,则a+b*t和b也互质,即与a互质的数对a取模具有周期性. 所以只要求出小于n且与n互质的元素即可. #include&l ...
- POJ 3696 The Luckiest number (欧拉函数,好题)
该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^ ...
- POJ 3090 Visible Lattice Points 【欧拉函数】
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...
- nyoj 1007 GCD(数学题 欧拉函数的应用)
GCD 描述 The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b) ...
- 题解报告:poj 2480 Longge's problem(欧拉函数)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
- 【poj 2407】Relatives(数论--欧拉函数 模版题)
题意就是求10^9以内的正整数的欧拉函数(Φ(n)表示<=n的与n互质的正整数个数). 解法:用欧拉筛和欧拉函数的一些性质: 1.若p是质数,Φ(p)=p-1: 2.欧拉函数是积性函 ...
- POJ_2478 Farey Sequence 【欧拉函数+简单递推】
一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...
- poj 1284 Primitive Roots(原根+欧拉函数)
http://poj.org/problem?id=1284 fr=aladdin">原根 题意:对于奇素数p,假设存在一个x(1<x<p),(x^i)%p两两不同(0&l ...
随机推荐
- [ZPG TEST 117] 跑路【构图】
一看懵了,求一条路的长度whose二进制位中1的个数最小?什么鬼. 其实这种n这么小的图论题,应该往Floyd上想了.令f(p, i, j)为从i走长度为2^p长度的路能否到j,若能,则在一张新的图上 ...
- Linux环境下Apache反向代理金蝶中间件Apusic集群
操作系统:RedHat Enterprise Linux 5.6 文档参考:<金蝶Apusic应用服务器 帮助手册| IX. Apusic Http Server使用指南> 一.金蝶中间件 ...
- d3学习笔记
(1)使用enter()函数. 当要创建新的绑定数据的元素,必须使用enter().这个方法会分析当前选择的DOM元素和传给它的数据,如果数据值比对应的DOM元素多,就创建一个新的占位元素.然后把这个 ...
- C# 代码笔记_tuple元组
tuple元组: 赋值 List<Tuple<string, int>> cc = new List<Tuple<string, int>>() { n ...
- CAS server 连接mysql的deployerConfigContext.xml配置
1.deployerConfigContext.xml配置 <?xml version="1.0" encoding="UTF-8"?> <b ...
- 阿里云服务器安装ss使用
下载安装服务器版shadowsocks yum install epel-release yum update yum install python-setuptools m2crypto super ...
- jq一些常用的交互效果
jq回到顶部: //回到顶部 $(window).scroll(function() { //执行处理的代码 var a = document.body.scrollTop; if($(documen ...
- Ubuntu Linux14 64位下在Android studio下用gradle编译Andrid项目时发生libz.so.1共享库找不到的解决方法。
---恢复内容开始--- 我在Ubuntu14 64为下安装了AS,但在用Gradle编译项目时总是报找不到 libz.so.1的错误. error while loading shared libr ...
- h5 移动端 监听软键盘弹起、收起
前面一篇博客 h5 安卓 键盘弹起界面适配 修改webview高度提到了在adnroid中如何监听软键盘的弹起与收起,是利用的窗口的高度发生变化window.onresize事件来做突破点的,但是io ...
- apropos - 在 whatis 数据库中查找字符串
总览 (SYNOPSIS) apropos keyword ... 描述 (DESCRIPTION) apropos 命令在一些特定的包含系统命令的简短描述的数据库文件里查找关键字, 然后把结果送到标 ...