hdoj-【5597 GTW likes function】

GTW likes function

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


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

主要是打表找一下规律,不知道是不是遇到这样的题目都可以打个表吗? 以后做一下这一类的题目;看有没有这个共性

#include<cstdio>
#include<cmath>
int f(int a,int b)
{
	int i,sum=1;
	for(i=1;i<=b;++i)
		 sum*=i;
	int up=1;
	while(b--)
	{
		up*=a;
		a-=1;
	} 
	return up/sum;
} 
int main()
{
	int i,k;
	for(i=0;i<10  ;++i)
	{
		int sum=0;
		for(k=0;k<=i;++k)
		{
			sum+=pow(-1,k)*pow(4,i-k)*f(2*i-k+1,k); 
		}
		printf("%d %d\n",i,sum); 
	} 
	return 0;
}


#include<cstdio>
typedef long long LL;

int main() 
{
	LL n,x;
	while(~scanf("%lld%lld",&n,&x))
	{
		LL i,ans=n+x+1;
		n=ans;
		for(i=2;i*i<=n;++i) 
		{
			if(n%i==0)
			{
				ans=ans/i*(i-1);//这个地方需要注意,会超long long 的 
				while(n%i==0)
					n/=i; 
			} 
		} 
		if(n!=1)
			ans=ans/n*(n-1);
		printf("%lld\n",ans); 
	} 
	return 0;
} 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值