Gold Coins

From Progteam

Revision as of 15:26, 23 May 2008 by Mlc413 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Checkmark.jpg This problem has been solved by Mlc413.


Gold Coins
Problem Number 2000
Sorter: mlc413
Source: Unknown
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=2000



Gold Coins is problem number 2000 on the Peking University ACM site.


import java.util.*;

public class Main{

    public static Scanner in;
 
    public static void main(String[] args){
        in=new Scanner(System.in);

        doStuff();
    }

    public static void doStuff(){
        int N=in.nextInt();

	while(N!=0){
            solve(N);
	    N = in.nextInt();
        }
    }

    public static void solve(int N){
	int total = 0;
	int N_ = N;
	int days = 1;
	while(N>0){
	    total += days*days;
	    N-=days;
	    days++;
	}
	if(N < 0){
	    total -= -1*(N)*(days-1);
	}
	
	System.out.println(N_ + " " + total);
    }
}

Personal tools