Gym - 101727D Interview Task [欧拉函数]
2018-02-17 18:24
295 查看
题意:初始第一步给你两个1,然后一直在相邻两数之间插一个两数之和,问第n步的时候数值等于n的数有多少个。
题解:打表发现是欧拉函数= =,1的时候要特判。
AC代码:
#include<stdio.h>
#include<math.h>
typedef long long ll;
ll GetPhi(ll n)
{
ll m=sqrt(n+0.5);
ll ans=n;
for(ll i=2;i<=m;i++)
if(n%i==0)
{
ans=ans/i*(i-1);
while(n%i==0)n/=i;
}
if(n>1)ans=ans/n*(n-1);
return ans;
}
int main()
{
ll n;
scanf("%lld",&n);
if(n==1)printf("2\n");
else printf("%lld\n",GetPhi(n));
}
题解:打表发现是欧拉函数= =,1的时候要特判。
AC代码:
#include<stdio.h>
#include<math.h>
typedef long long ll;
ll GetPhi(ll n)
{
ll m=sqrt(n+0.5);
ll ans=n;
for(ll i=2;i<=m;i++)
if(n%i==0)
{
ans=ans/i*(i-1);
while(n%i==0)n/=i;
}
if(n>1)ans=ans/n*(n-1);
return ans;
}
int main()
{
ll n;
scanf("%lld",&n);
if(n==1)printf("2\n");
else printf("%lld\n",GetPhi(n));
}
相关文章推荐
- [构造] Codeforces Gym 101173 CERC 16 K & BZOJ 4796 Key Knocking
- Gym - 100623I Important Wires
- [BZOJ]4805: 欧拉函数求和
- [可图性判定 Havel-Hakimi定理 构造] Codeforces Gym 100269 NEERC 13 Northern K. Kids in a Friendly Class
- gym 100765A Sasha vs. Kate
- bzoj4805: 欧拉函数求和
- 找新朋友 欧拉函数
- Gym - 100765C King Berl VI 差分约束
- Gym - 100187E E - Two Labyrinths —— bfs
- Gym - 101350E-Competitive Seagulls-博弈-思维
- Gym 101246E Kidnapping 递推or dfs 优化
- Gym 101097I Sticks (思维)
- codeforces gym 100357 K (表达式 模拟)
- [Gym-100520F]
- Gym - 100520D
- Gym - 100712G Heavy Coins(二进制枚举)
- Gym - 101341I Matrix God
- hdu2588 GCD 给定n,m。求x属于[1,n]。有多少个x满足gcd(x,n)>=m; 容斥或者欧拉函数
- 欧拉函数概念及其证明
- Gym 101147J Whistle's New Car(dfs)