hdu 5597GTW likes function(欧拉函数)

时间:2022-12-15 23:05:40

题目链接:【hdu 5597】

f(n)=sum((-1)^k * 2^(2n-2k) * C(k, 2n-k+1))   0<=k<=n

这个公式化简之后就是f(x) = x+1

简单证明一下

首先要知道C(m,n)+C(m+1, n) = C(m+1, n+1)

hdu 5597GTW likes function(欧拉函数)

<span style="font-size:14px;">#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
#define ll __int64
int main()
{
	ll n, x;
	while(~scanf("%I64d%I64d", &n, &x))
	{
		x = n+x+1;
		ll ans=x;
		for(ll i=2; i*i<=x; i++)
		{
			if(x%i==0) 
			{
				ans=ans/i*(i-1);
				while(x%i==0) x/=i;
			}
		}
		if(x>1) ans=ans/x*(x-1);
		printf("%I64d\n", ans);
	}
	return 0;
}</span>