题目链接:
GTW likes function
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
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
题意:
给这么一个函数,问euler(fn(x))为多少;
思路:
发现f0(x)=x+1;fn(x)=f(fn-1(x))=f0(fn-1(x))=fn-1(x)+1=f0(x)+n=x+n+1;
再就是O(sqrt(n))复杂度找到euler(x+n+1);
AC代码:
//#include <bits/stdc++.h> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; #define Riep(n) for(int i=1;i<=n;i++) #define Riop(n) for(int i=0;i<n;i++) #define Rjep(n) for(int j=1;j<=n;j++) #define Rjop(n) for(int j=0;j<n;j++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; const LL mod=1e9+7; const double PI=acos(-1.0); const int inf=0x3f3f3f3f; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar()); for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + ‘0‘); putchar(‘\n‘); } LL n,x; int main() { while(cin>>n>>x) { LL sum=n+x+1,ans; ans=sum; for(LL i=2;i*i<=n+x+1;i++) { if(sum%i==0) { ans=ans/i*(i-1); while(sum%i==0)sum/=i; } } if(sum>1)ans=ans/sum*(sum-1); cout<<ans<<"\n"; } return 0; }