HDOJ 5597 GTW likes function (欧拉函数)
来源:互联网 发布:windows微信是什么 编辑:程序博客网 时间:2024/06/04 00:33
GTW likes function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 226 Accepted Submission(s): 123
Problem Description
Now you are given two definitions as follows.
f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1)
Note thatφ(n) means Euler’s totient function.(φ(n) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n.)
For each test case, GTW has two positive integers —n and x , and he wants to know the value of the function φ(fn(x)) .
Note that
For each test case, GTW has two positive integers —
Input
There is more than one case in the input file. The number of test cases is no more than 100. Process to the end of the file.
Each line of the input file indicates a test case, containing two integers,n and x , whose meanings are given above. (1≤n,x≤1012)
Each line of the input file indicates a test case, containing two integers,
Output
In each line of the output file, there should be exactly one number, indicating the value of the functionφ(fn(x)) of the test case respectively.
Sample Input
1 12 13 2
Sample Output
222题意:应该都能看懂就不翻译了思路:其实这个挺简单的,列几组数据,然后就会发现往下递归几次最后num就是加上了几+1,也就是说num的变化值为n+1,而num的初始值呢,当你列出几组数据会发现,x=1的时候num=1,x=2的时候,num=2;,所以说最后的num=x+n+1,所以ans=eular(num)。。。ac代码:#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 60001#define LL long long#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;LL eular(LL n){ LL i,res=n; for(i=2;i*i<=n;i++) if(n%i==0) { res=res/i*(i-1); while(n%i==0) n/=i; } if(n>1) res=res/n*(n-1); return res; }int main(){ LL n,x; while(scanf("%I64d%I64d",&n,&x)!=EOF) { printf("%I64d\n",eular(n+x+1)); } return 0;}
0 0
- HDOJ 5597 GTW likes function (欧拉函数)
- HDOJ 5597 GTW likes function(规律+欧拉函数)
- hdu 5597 GTW likes function(欧拉函数)
- hdu 5597GTW likes function(欧拉函数)
- hdoj GTW likes function 5597 (裸欧拉函数)
- hdoj-【5597 GTW likes function】
- hdoj 5597 GTW likes function 【打表找规律】
- HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)
- hdu 5597 GTW likes function
- hdu-5597 GTW likes function
- HDU 5597 GTW likes function
- hdu 5597 GTW likes function
- HDOJ 5595 GTW likes math 【二次函数】
- 杭电5597GTW likes function
- hdu5597GTW likes function 欧拉函数
- hdu5597GTW likes function+欧拉函数
- hdoj GTW likes math 5595 (暴力)
- HDOJ--5595--GTW likes math
- .NET框架
- JavaScript 正在蚕食着开发领域
- 封装canvas的插件-KineticJs
- 验证折半查找算法
- 快速排序
- HDOJ 5597 GTW likes function (欧拉函数)
- v4l2采集MJPG然后保存为JPG
- 主从表的创建,查询代码待增加
- scala并发编程第8章习题1-3
- [Python标准库]re——正则表达式[三]
- uva 10271——Chopsticks
- 第十三周实践项目~Kruskal算法的验证
- 验证分块查找算法
- javaweb常用工具类及配置文件备份