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 shr1992 at 2009-07-21 14:24:49 on Problem 2000
考虑清楚了就好了……
直接贴代码……
Source Code

Problem: 2000  User: shr1992 
Memory: 132K  Time: 0MS 
Language: C++  Result: Accepted 

Source Code 
#include<iostream>
using namespace std;
int main()
{
	int n,i,x=0;
	scanf("%d",&n);
	while(n!=0){
		for(i=1;i<=n;i++){
			if(n==i*(i+1)/2){
				x=i*(i+1)*(2*i+1)/6;
				break;
			}
			if(n<i*(i+1)/2){
				x=i*(i-1)*(2*i-1)/6+i*(n-i*(i-1)/2);
				break;
			}
		}
		printf("%d %d\n",n,x);
		scanf("%d",&n);
		x=0;
	}
	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