GTW likes function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 92 Accepted Submission(s): 54
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)) .
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)
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)=f0(x)=∑k=0x(−1)k22x−2kC2x−k+1k,fn(x)=f(fn−1(x))(n≥1)f(x)=f_{0}(x)=\sum_{k=0}^{x}(-1)^{k}2^{2x-2k}C_{2x-k+1}^{k},f_{n}(x)=f(f_{n-1}(x))(n\geq 1)f(x)=f0(x)=∑k=0x(−1)k22x−2kC2x−k+1k,fn(x)=f(fn−1(x))(n≥1) φ(n)\varphi(n)φ(n)为欧拉函数。指的是不超过nnn的与nnn互质的正整数个数。 对于每组数据,GTW有两个正整数n,xn,xn,x,现在他想知道函数φ(fn(x))\varphi(f_{n}(x))φ(fn(x))的值。 输入描述 输入有多组数据,不超过100组。每数据输入一行包含2个整数组nnn和xxx。(1≤n,x≤1012)(1\leq n,x \leq 10^{12})(1≤n,x≤1012) 输出描述 对于每组数据输出一行,表示函数φ(fn(x))\varphi(f_{n}(x))φ(fn(x))的值。 输入样例 1 1 2 1 3 2 输出样例 2 2 2
#include<stdio.h> #include<string.h> #include<algorithm> #define ll long long using namespace std; ll eular(ll n) { ll i,j,ans=n; for(i=2;i*i<=n;i++) { if(n%i==0) { ans=ans/i*(i-1); while(n%i==0) n/=i; } } if(n>1) ans=ans/n*(n-1); return ans; } int main() { ll n,x; while(scanf("%lld%lld",&n,&x)!=EOF) printf("%lld\n",eular(n+x+1)); return 0; }