POJ-2000 Gold Coins
Gold Coins
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 21914 | Accepted: 13732 |
Description
The king pays his loyal knight in gold coins. On the first day of his service, the knight receives one gold coin. On each of the next two days (the second and third days of service), the knight receives two gold coins. On each of the next three days (the fourth,
fifth, and sixth days of service), the knight receives three gold coins. On each of the next four days (the seventh, eighth, ninth, and tenth days of service), the knight receives four gold coins. This pattern of payments will continue indefinitely: after
receiving N gold coins on each of N consecutive days, the knight will receive N+1 gold coins on each of the next N+1 consecutive days, where N is any positive integer.
Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from Day 1).
Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from Day 1).
Input
The input contains at least one, but no more than 21 lines. Each line of the input file (except the last one) contains data for one test case of the problem, consisting of exactly one integer (in the range 1..10000), representing the number of days. The end
of the input is signaled by a line containing the number 0.
Output
There is exactly one line of output for each test case. This line contains the number of days from the corresponding line of input, followed by one blank space and the total number of gold coins paid to the knight in the given number of days, starting with
Day 1.
Sample Input
10 6 7 11 15 16 100 10000 1000 21 22 0
Sample Output
10 30 6 14 7 18 11 35 15 55 16 61 100 945 10000 942820 1000 29820 21 91 22 98
Source
#include<iostream>
#include<cmath>
using namespace std;
/*n*(n+1)/2是最終的和
1*1+2*2+3*3+...+n*n = n*(n+1)*(2*n+1)/6*/
int main()
{
int n,sum,x;
cin>>n;
while(n!=0)
{
sum=0;
cout<<n<<" ";
x=ceil((sqrt(1.0+8.0*n)-1.0)/2.0);
sum=x*(x+1)*(2*x+1)/6-x*((x*(x+1)/2)-n);
cout<<sum<<endl;
cin>>n;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n,ans;
cin>>n;
while(n)
{
ans=0;
for(int i=0,j=1; i<=n; j++)
{
int k=j;
while(k--&&++i<=n)
ans+=j;
}
cout<<n<<" "<<ans<<endl;
cin>>n;
}
return 0;
}
相關文章
- YT15-HDU-Harry's parents had left him a lot of gold coinsGo
- How to create the Gold gold using RGB color values All In OneGo
- Lesson 55 - Not a gold mineGo
- Deals for 07 Runescape GoldGo
- In this new Buy fifa coins? area
- EverQuest Buy fifa coins site launched
- GameSpot How is Buy fifa coins? developmentGAMdev
- Bitcoin Gold 遭遇雙花攻擊Go
- WinBoost 2000 Gold 破解教程Go
- The Buy fifa coins Xbox is saidAI
- [Atcoder DP I]Coins 題解
- WoW Gold: Baron Soosdon - UNLIMITED Escapism Vol 5GoMITAPI
- 【Leetcode】441. Arranging CoinsLeetCode
- Sony Pictures Buy fifa coins ? Digital EntertainmentGitAI
- but youre quickly Fifa 14 ultimate team coins bombardedUI
- Leetcode 441. Arranging CoinsLeetCode
- HDOJ-1398 Square Coins(母函式)函式
- 「SWTR-4」Collecting Coins 題解
- AT&T has not set cheap wow gold an end dateGo
- ePublisher Gold v1.4 (9千字)Go
- Leetcode 解析 (441. Arranging Coins)LeetCode
- Where do you go Fifa 14 ultimate team coins afterGo
- Typing Instructor Gold for Mac打字練習軟體StructGoMac
- Nintendo itself Fifa 14 ultimate team coins isnt bringing
- PAX Gold(PAXG)質押系統搭建開發技術Go
- lightoj 1030 Discovering Gold (基礎概率dp)Go
- RealPlayer10GOLD.bin的安裝問題?(轉)Go
- [Gold week hot : 掘金一週熱門] 第一期Go
- bzoj1770 USACO NOV09 GOLD 燈(暴力出奇跡)Go
- B - Gold Balanced Lineup解題報告(張浩盛倫)Go
- HDU3519Lucky Coins Sequence(DP+矩陣加速)矩陣
- 【USACO 2015 Open Gold】Palindromic Paths 動態規劃Go動態規劃
- 杭電ACM hdu 1398 Square Coins 解題報告(母函式)ACM函式
- [USACO 2009 Feb Gold] Fair Shuttle (貪心+優先佇列)GoAI佇列
- BTG(bitcoin gold)受到51%攻擊,攻擊者利用雙重支付獲利Go
- 利用ld.gold將程式編譯成llvm中的BitcodeGo編譯LVM
- ePublisher Gold v1.3 的註冊碼及序號產生器Go
- LeetCode C++ 441. Arranging Coins【Math/Binary Search】簡單LeetCodeC++