Heritage from FatherTime
limit:2000/1000 MS (java/others) Memory limit:131070/65535 K (java/others)
Total submission (s): 6076 Accepted Submission (s): 2214
Problem descriptionfamous Harry potter,who seemd to be a normal and poor boy,is actually a wizard. Everything changed when he had his birthday of ten years old. A huge man called ' Hagrid ' found Harry and leads him to a new world full of magic power.
If you've read this story,you probably know that Harry's parents had left him a lot of gold coins. Hagrid leads Harry to Gringotts (the bank hold up by goblins). And they stepped into the "the" which stored the fortune from his father. Harry was astonishing, coz there were piles of gold coins.
The packing these coins by goblins is really special. Only one coin is on the Top,and three coins consisted a triangle were on the next lower layer. The third layer has six coins which were also consisted a triangle,and so on. On the ith layer there is an triangle has I coins each edge (totally i* (i+1)/2). The whole heap seemed just like a pyramid. Goblin still knew the total num of the layers,so it's up and help Harry to figure out the sum of the the coins.
Inputthe input would consist of some Cases,each case takes a line with only one integer N (0<n<2^31). It ends with a single 0.
Output for each input n, outputs a line, using scientific notation to calculate the total number of coins (retain three significant digits)
Sample Input
130
Sample Output
1.00e01.00e1HintHintwhen N=1, there is 1 gold coins. When n=3, there is 1+3+6=10 gold coins.
Sourcegardon-dygg Contest 1
recommendjgshining | We have carefully selected several similar problems for you:1205 1030 1143 1181 1014
#include <stdio.h> #include <math.h>int main () {int n;while (scanf ("%d", &n), N) {double t=1.0*n* (n+1) * (n +2)/6; Here to use double type, double the index range is much larger than __int64, so the previous __int64, the result has been wa!! int k= (int) log10 (t);d ouble A=pow (10,LOG10 (t)-K);p rintf ("%.2lfe%d\n", A,k);}}
float:
1bit (sign bit) 8bits (digit digit) 23bits (trailing digit)
Double:
1bit (sign bit) 11bits (digit digit) 52bits (trailing digit)
Thus, float has an exponential range of -127~+128, and a double has an exponential range of -1023~+1024
s=1*2+2*3+3*4+...+n* (n+1) =n* (n+1) * (n+2)/3;=>> for the first n of i* (i+1) and, can be split into: I^2,i, respectively, to find the first N and
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj-1178-heritage from father "scientific notation"