AnInterestingSequence
来源:互联网 发布:android ant mac下载 编辑:程序博客网 时间:2024/05/17 01:17
YiYi is a smartboy, he is fascinated in solving eccentric problems. One day when he wasreading a book, he came across a very interesting problem. After a few time’sthinking, he finally get the solution. YiYi considers this solution veryheuristic, now he decides to show this problem to you so that you can alsoenjoy the happiness of solving this interesting problem. Here is thedescription of the problem:
Suppose at firstyou have a sequence, S1, consists of two numbers: 1, 1.According to some rule you can get the sequence Sn from thesequence Sn-1.Once you get Sn-1, you will be asked to insert one nbetween a and b if a and b are two adjacent numbers in Sn-1 and a + b = n. After you have inserted all possible n you finally get Sn.You can also get the sequence Sn+1 using the same method and so on.
For example,S1 =1,1.Since 1 + 1 = 2, we will insert 2 between two 1s and then we get S2, S2 = 1,2,1.Now we will insert two 3s in the sequence to get S3, as you cansee, S3 = 1,3,2,3,1. In the same way, we know S4 =1,4,3,2,3,4,1, S5 = 1,5,4,3,5,2,5,3,4,5,1 and so on.
Here thequestion comes: give you n, you will be asked to output the number of n in Sn.For example if n = 5, you will output 4 since there are 4 5s in S5.
输入
输出
样例输入
3245
样例输出
124#include<stdio.h>
long long eular(long long n){
long long ret=1,i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
n/=i,ret*=i-1;
while(n%i==0)
n/=i,ret*=i;
}
}
if(n>1) ret*=n-1;
return ret;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
long long n;
scanf("%lld",&n);
printf("%lld\n",eular(n));
}
return 0;
}
- AnInterestingSequence
- 准备面试需要知道的经典算法--堆排序
- BFS(广搜) 骑士旅行
- DevStack环境搭建
- 解决MINGW64、Git Bash命令不能回退的问题
- 一篇故事讲述了计算机网络里的基本概念:网关,DHCP,IP寻址,ARP欺骗,路由,DDOS等
- AnInterestingSequence
- 利用tensorflow制作一个简单的聊天机器人
- spring MVC国际化的简单实现
- Android.mk文件分析
- SODBASE CEP事件驱动应用----实时支付对账
- javascript中string和json转化方法
- (十八)享元模式详解(都市异能版)
- jQuery 性能优化
- 在Android Studio中实现AIDL远程服务调用