BestCoder Round #66 (div.2)1003 GTW likes function HDU5597

49 篇文章 0 订阅
35 篇文章 0 订阅


GTW likes function

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


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 1 2 1 3 2
 

Sample Output
  
  
2 2 2
 

Source

出题人:

由打表找规律可得,\sum_{k=0}^{x}(-1)^{k}2^{2x-2k}C_{2x-k+1}^{k}=x+1k=0x(1)k22x2kC2xk+1k=x+1,所以显然f_n(x)=n+x+1fn(x)=n+x+1

因此直接求\varphi(n+x+1)φ(n+x+1)。时间效率O(T\sqrt{n})O(Tn)

严格证明:

a_n=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k+1}^kan=k=0n(1)k22n2kC2nk+1k

a_n=2^{2n}+\sum_{k=1}^{n}(-1)^k2^{2n-2k}(C_{2n-k}^k+C_{2n-k}^{k-1})=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k}^k+\sum_{k=0}^{n-1}(-1)^{k+1}2^{2(n-1)-2k}C_{2(n-1)-k+1}^kan=22n+k=1n(1)k22n2k(C2nkk+C2nkk1)

=k=0n(1)k22n2kC2nkk+k=0n1(1)k+122(n1)2kC2(n1)k+1k

b_n=\sum_{k=0}^{n}(-1)^k2^{2n-2k}C_{2n-k}^kbn=k=0n(1)k22n2kC2nkk,则b_n=a_n+a_{n-1}bn=an+an1

b_n=2^{2n}+\sum_{k=1}^{n-1}(-1)^k2^{2n-2k}(C_{2n-k-1}^k+C_{2n-k-1}^{k-1})+(-1)^nbn=22n+k=1n1(1)k22n2k(C2nk1k+C2nk1k1)+(1)n

=4\sum_{k=0}^{n-1}(-1)^k2^{2(n-1)-2k}C_{2(n-1)-k+1}^k+\sum_{k=0}^{n-1}(-1)^{k+1}2^{2(n-1)-2k}C_{2(n-1)-k}^k=4k=0n1(1)k22(n1)2kC2(n1)k+1k+k=0n1(1)k+122(n1)2kC2(n1)kk

=4a_n-b_{n-1}=4anbn1

a_n-a_{n-1}=a_{n-1}-a_{n-2}anan1=an1an2。因为a_0=1,a_1=1a0=1,a1=1,所以a_n=n+1an=n+1

证明比较费时,打表找规律能很快的得出解,所以本题的关键在于打表找规律。


#include 
   
   
    
    
#include 
    
    
     
     
using namespace std;
long long euler(long long n)  //返回euler(n)
{
    long long res=n,a=n;
    for(long long i=2; i*i<=a; i++)
    {
        if(a%i==0)
        {
            res=res/i*(i-1);//先进行除法是为了防止中间数据的溢出
            while(a%i==0) a/=i;
        }
    }
    if(a>1) res=res/a*(a-1);
    return res;
}
int main()
{
    long long n,x,i;
    while(~scanf("%lld%lld",&n,&x))
    {
        printf("%lld\n",euler(x+n+1));
    }
    return 0;
}
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值