Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

二种方法!!!!!!!!!!!!!!!!!!!!!!!

Posted by 731371663 at 2011-02-14 15:19:12 on Problem 2853
//方法一:
/*  假设连续数的第一个数为a,有n个连续数,他们的和为M,这样的话就有:
(a+(a+n-1))*n =(2*a+n-1)*n = 2*M,从这个式子我们可以得到n<sqrt(2*M)=sqrt(2)*sqrt(M)<2*sqrt(M),
也就是说:n<2*sqrt(M),要求解方程(2*a+n-1)*n = 2*M(其中,我们把a当作未知数)
因为a为自然数,所以要满足以下条件:
1)2*M/n为一个整数;
2)2*M/n+1-n为一个整数;
3)(2*m/n+1-n)/2为一个正整数;
*/
/*
#include<iostream>
#include<cmath>


int main()
{
	//freopen("in.txt","r",stdin);
	int i,t,n,num_i,sum;
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		scanf("%d%d",&num_i,&n);
		for(i=2;i<(int)sqrt((double)n)*2;i++)
		{
			if(2*n%i==0&&2*n/i+1-i>0&&(2*n/i+1-i)%2==0)
				sum++;
		}
		printf("%d %d\n",num_i,sum);
	}
	return 0;
}*/

//方法二:
/*
1.	这串连续的整数可以表示为:(x+1)+(x+2)+(x+3)+(x+4)+……+(x+i)  , 其中x=0,1,2 ...... 
2.	假设已经找到:(x+1)+(x+2)+(x+3)+(x+4)+……+(x+i) =number; 
3.	A=number-(1+2+3+......+i)=number-(1+i)*i/2; 
4.	A=x*i;即A一定能被i整除,从而达到判定目的.
*/

#include<iostream>

int main()
{
	//freopen("in.txt","r",stdin);
	int i,t,n,sum,num_i;
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		scanf("%d%d",&num_i,&n);
		for(i=2;n>=(i+1)*i/2;i++)
		{
			if((n-(i+1)*i/2)%i==0)
				sum++;
		}
		printf("%d %d\n",num_i,sum);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator