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
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
题意:已知f(x),求欧拉函数;
思路:通过枚举f1(0)=1+0+1=2,
f1(1)=1+1+1=3,
f1(2)=1+2+1=4,
f1(3)=1+3+1=5,
f2(1)=2+1+1=4;
得fn(x)=n+x+1;
将其返回值带入欧拉函数模板便可得结果;
#include<stdio.h>
long long euler(long long n) //欧拉函数
{
long long res=n,a=n;
for(long long i=2;i*i<=a;i++)
{
if(a%i==0)
{
res=res/i*(i-1);
while(a%i==0)
a/=i;
}
}
if(a>1)
res=res/a*(a-1);
return res;
}
int main ()
{
long long n,x;
while(~scanf("%I64d%I64d",&n,&x))
{
printf("%I64d\n",euler(n+x+1));
}
return 0;
}