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≤10^12)
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)
f0(1)=2,f0(2)=3
f1(1)=3,f1(2)=4
f2(1)=4,f2(2)=5
so..猜一发
fn(x)=n+x+1
直接求欧拉函数就好。。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
LL eular(LL n){
LL ans=n;
for(LL i=2;i*i<=n;i++){
if(n%i==0){
ans-=ans/i;
while(n%i==0) n/=i;
}
}
if(n>1) ans-=ans/n;
return ans;
}
int main(){
ios::sync_with_stdio(false);
LL n,x;
while(cin>>n>>x){
cout<<eular(n+x+1)<<endl;
}
return 0;
}