您的位置:首页 > 编程语言 > Go语言

zoj 2345 Gold Coins

2012-03-31 12:40 316 查看
//这题主要是找一下规律就可以了:1^2 + 2^2 + 3^2 + ..... + n^2
#include "iostream"
#include "memory.h"
using namespace std;

int main()
{
int testcase, i, days, coins, temp, remain;
cin >> testcase;
while (testcase--)
{
while (cin >> days && days)
{
coins = 0;
temp = 1;
for (i = 1; temp <= days; i++, temp += i)
{
coins += i * i;
}
remain = (days - (temp-i)) * i;
coins += remain;
cout << days << " " << coins << endl;
}
if (testcase)
cout << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: