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 fanrongqi at 2011-01-06 14:32:03 on Problem 1019

#include <iostream>
using namespace std;


int main(){

	unsigned long i;
	int num;
	int s1;
   unsigned  long j;
	 cin>>num;
	 while(num--){ 
		 cin>>i;
		s1=1;
		if (i==1 || i==2)//最开始的3个就特殊处理
		{
			cout<<1<<endl;
			break;
		}
		if (i==3)
		{
			cout<<2<<endl;
			break;
		}
			j=1;
		while(1){
			if (j*(j+1)>=2*i)//等差数列求和公式
			{
				break;
			} 
			else
			{
				s1=j*(j+1)/2;
			}
			j++;
		}
		i=i-s1;
		if (i==0)
		{
			cout<<j<<endl;
		} 
		else
		{
			cout<<i<<endl;
		}
		 
	}




	return 1;
}









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