hdoj5597GTW likes function【找规律+欧拉函数】
2015-12-14 16:31
411 查看
GTW likes function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 241 Accepted Submission(s): 132
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)).
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)
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 1
2 1
3 2
Sample Output
2
2
2
Source
BestCoder Round #66 (div.2)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long Euler(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()
{
long long n,x;
while(scanf("%lld%lld",&n,&x)!=EOF){
printf("%lld\n",Euler(n+x+1));
}
return 0;
}
相关文章推荐
- error: no matching function for call to
- type void func(int)
- 中国功夫-chinese kung fu
- Formal System-Hilbert计算(Hilberkalkül)
- 安卓学习网址
- 卷积神经网络
- Tcp 连接出现大量ESTABLISHED连接
- 下载功能
- @proprety数组字典字符串用copy和strong区别(深浅拷贝)
- Node.js内置的工具和第三方模块来进行单步调试
- 20151214
- Asio驱动开发学习笔记(2)
- Git 版本回退
- 第十五周 项目1 排序(基数排序)
- Android setImageResource、setImageBitmap、setImageDrawable区别
- 十六周 项目1希尔排序
- 第十六周项目2希尔排序
- 百度实习生面试经历
- CSS的一些简单概念
- php数组函数-array_push()