HDOJ 5597 GTW likes function (欧拉函数)

来源:互联网 发布:windows微信是什么 编辑:程序博客网 时间:2024/06/04 00:33

GTW likes function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 226    Accepted Submission(s): 123


Problem Description
Now you are given two definitions as follows.

f(x)=xk=0(1)k22x2kCk2xk+1,f0(x)=f(x),fn(x)=f(fn1(x))(n1)

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. (1n,x1012)
 

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 12 13 2
 

Sample Output
222题意:应该都能看懂就不翻译了思路:其实这个挺简单的,列几组数据,然后就会发现往下递归几次最后num就是加上了几+1,也就是说num的变化值为n+1,而num的初始值呢,当你列出几组数据会发现,x=1的时候num=1,x=2的时候,num=2;,所以说最后的num=x+n+1,所以ans=eular(num)。。。ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 60001#define LL long long#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;LL eular(LL n){      LL i,res=n;      for(i=2;i*i<=n;i++)          if(n%i==0)        {              res=res/i*(i-1);              while(n%i==0)            n/=i;          }      if(n>1)     res=res/n*(n-1);      return res;  }int main(){    LL n,x;    while(scanf("%I64d%I64d",&n,&x)!=EOF)    {        printf("%I64d\n",eular(n+x+1));    }    return 0;}


0 0
原创粉丝点击