GTW likes function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 393 Accepted Submission(s): 212
Problem Description
Now you are given two definitions as follows.
f(x)=∑
x
k=0
(−1)
k
2
2x−2k
C
k
2x−k+1
,f
0
(x)=f(x),f
n
(x)=f(f
n−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
φ(f
n
(x))
.
f(x)=∑
Note that φ(n)
For each test case, GTW has two positive integers — n
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
)
Each line of the input file indicates a test case, containing two integers, n
Output
In each line of the output file, there should be exactly one number, indicating the value of the function
φ(f
n
(x))
of the test case respectively.
Sample Input
1 1 2 1 3 2
Sample Output
2 2 2
出题人真会玩,暴力按照题干要求解题提交会爆栈。最后要找到规律才行,题干中的fn(x)的值就是n+x+1.然后就要用到一个欧拉函数的东西,自行百度:说真的这道题能AC挺不容易的
#include<iostream>
#include<stdio.h>
using namespace std;
long long eular(long long n)
{
long long res=1,i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
n/=i;res*=i-1;
while(n%i==0)
{
n/=i;res*=i;
}
}
}
if(n>1)
{
res*=n-1;
}
return res;
}
int main()
{
long long n,x;
while(scanf("%I64d%I64d",&n,&x)!=EOF)
printf("%I64d\n",eular(x+n+1));
return 0;
}