HDU 1178 Heritage from father 数学公式 JAVA

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情
题意:求 ni=1i(i+1)2 ,并用科学计数法保留3位小数表示出来。
思路:写出公式即可: ni=1i(i+1)2=12ni=1(i2+i)=12[n(2n+1)(n+1)6+i(i+1)2]
我菜成狗的 java ,吐槽一下,java的BigInteger写起来好爽呀,都是泪。

http://acm.hdu.edu.cn/showproblem.php?pid=1178

/*********************************************
    Problem : HDU 1178
    Author  : NMfloat
    InkTime (c) NM . All Rights Reserved .
********************************************/

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String argv[]) {
        Scanner cin = new Scanner(System.in);
        BigInteger two = BigInteger.valueOf(2);
        BigInteger six = BigInteger.valueOf(6);
        BigInteger n , ans;
        while(cin.hasNext()) {
            n = cin.nextBigInteger();
            if(n.compareTo(BigInteger.ZERO)==0) break;
            ans = n.multiply(n.multiply(two).add(BigInteger.ONE)).multiply(n.add(BigInteger.ONE)).divide(six);
            ans = ans.add(n.multiply(n.add(BigInteger.ONE)).divide(two)).divide(two);
            String a = ans.toString();
            char A[] = a.toCharArray();
            int lena = a.length();
            if(lena == 1) {
                System.out.printf("%s.00E%d",a,lena-1);
            }
            else if(lena == 2) {
                String b = a.substring(0,1);
                String c = a.substring(1,2);
                System.out.printf("%s.%s0E%d",b,c,lena-1);
            }
            else if(lena == 3) {
                System.out.printf("%c.%c%cE%d",A[0],A[1],A[2],lena-1);
            }
            else {
                if(A[3] >= '5') A[2] ++ ;
                if(A[2] > '9') { A[1] ++ ; A[2] = '0';}
                if(A[1] > '9') { A[0] ++ ; A[1] = '0';}
                if(A[0] > '9') {
                    lena ++;
                    A[0] = '1'; A[1] = '0'; A[2] = '0';
                }
                System.out.printf("%c.%c%cE%d",A[0],A[1],A[2],lena-1);
            }
            System.out.println("");
        }
    }
}
Hdu1178Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 5118    Accepted Submission(s): 1811 Problem Description Famous Harry Potter,who se 阅读详情

相关推荐

『杭电1178Heritage from father

Problem Description Famous 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 lead him to a new world full of magic power. If you

漠宸离若的博客 440

hdu1178(科学记数法)

#include int main() { double sum; int k,n; while(scanf("%d",&n)==1&&n) { k=0; sum=(n+1)*1.0*n/6.0*(n+2);//必须用n/6.0才能过 while(sum>=10) {

青山绿水之辈 专栏 1199

CGNS快速入门到实战(一):CGNS静态链接库编译

近期,由于需要将CGNS格式加入到教研组自编CFD求解器DUBHE中,所以本人展开了对于CGNS的学习。CGNS快速入门到实战这一系列分成三篇文章展开叙述,具体有:(一)CGNS静态链接库编译;(二)VS配置调用CGNS静态链接库编写;(三)CGNS文件及案例展示。本篇文章重点讲述CGNS静态链接库编译。

ahang_99的博客 3797

hdu---1178Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 4686    Accepted Submission(s): 1665 Problem Description Famous Harry

搬家啦x 649

hdu1178Heritage from father

水题,主要考察了一个数学公式; #include int main() {     int m,k;     double n;     while(scanf("%d",&m),m)     {         n=1.0*m*(m+1)*(m+2)/6.0;         k=0;         while(n>=10)         {            

飞雪---晨 766

hdu 1178 Heritage from father

这道题是基本的输出格式问题,还是那句话细节决定成败。 代码 1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 __int64 s,t; 7 double p,q; 8 while(scanf("%I64d",&s)!=EOF&&s) 9 ...

weixin_30363981的博客 112

hdu 1178

此題有纪念意义:如果两个int数很大,结果需要放到double型里面, 那么第一步请先乘以 1.0,转化成double型否则可能中间结果溢出,导致得不到正确答案 比如 int n; // n可能很大, double sum=0; sum=n*(n+1)*(n+2)/6.0; 如果我们不在第一步乘以1.0,那么n*(n+1) 可能就已经溢出,结果自然是错误的,所以正确的写法是。sum=1.0*n*

the_conquer_zzy的专栏 339

HDU1178 Heritage from father【水题】

Heritage from fatherTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 6899    Accepted Submission(s): 2584Problem DescriptionFamous Harry Potter,...

海岛Blog 1100

HDU 1178 Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 3783    Accepted Submission(s): 1335 Problem Description Famo

胖子加油! 911

HDU 1178Heritage from father

Heritage from father Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131070/65535K (Java/Other) Total Submission(s) : 73   Accepted Submission(s) : 26 Font: Times New Roman | Verdana | Geor

657

Heritage from father

Problem   Link:http://acm.hdu.edu.cn/showproblem.php?pid=1178 原题:

林下的码路 1184

hdu1178

求1,3,6,10,15,21,28……(n*())

穿袜子的流氓兔的专栏 769

hdu1178数学题 Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 5859Accepted Submission(s): 2107 Problem Description Famo...

weixin_30372371的博客 159

hdu 1178

http://acm.hdu.edu.cn/showproblem.php?pid=1178 等差求和公式s=n(n+1)/2=n/2+n^2/2。。。 sum=1+3+6+………………+i(i+1)(i+2)/6 =1+(1+2)+(1+2+3)+…………(1+2+3+……n) =1/2+1^2/2+2/2+2^2/2+…………n/2+n^2/2 =n(n+1)/2/2+n(n+1)(...

weixin_30575309的博客 123

hdu1178(简单公式)

题目链接:Heritage from father 计算 #include #include #include #include #include using namespace std; int main() { //freopen("in.txt","r",stdin); double n; while(scanf("%lf",

pmt123456的博客 398

hdu 1178 免费馅饼

题意:0~10的位置每秒掉馅饼,为最开始位置为5,每秒最多移动1,最后最多能接到多少馅饼。 设dp【i】【j】表示第i秒位置j接到的最多馅饼数量。 #include #include #include #include #include #include #include #include #include #include ///cout << fixed << setp

uuuuuu 347
上一篇: HDU 1177 "Accepted today?" 水题
下一篇: HDU 1164 Eddy's research I 数论
_NMfloat_
博客等级 码龄12年 7粉丝 315原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值