uva 10523 Very Easy !!!

来源:互联网 发布:阿里云 幕布申请 编辑:程序博客网 时间:2024/05/18 00:06

Very Easy !!!
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

Submit Status

Description

Download as PDF

THE SAMS' CONTEST

Problem 4

 VERY EASY !!! 

BACKGROUND

Most of the times, the students of Computer Science & Engineering of BUET deal with bogus, tough and very complex formulae. That is why, sometimes, even for a easy problem they think very hard and make the problem much complex to solve. But, the team members of the team "BUET PESSIMISTIC"  are the only exceptions. Just like the opposite manner, they treat every hard problem as easy and so cannot do well in any contest. Today, they try to solve a series but fail for treating it as hard. Let them help.

Input

Just try to determine the answer for the following series

You are given the value of and A (integer, 1<=N<=150  &  integer, 0<=A<=15) respectively.

Output

For each line of the input, your correct program should output the integer value of the sum in separate lines for each pair of values of N & A.

Sample Input

3 34 4

Sample Output

1021252

Anupam Bhattacharjee ( BUET PESSIMISTIC )

E means exponent, E means error. So try to avoid exponent whenever possible.



题意:计算图中的那个公式,给你的是n和a。

做法:直接用java大数来计算,非常方便。


import java.math.BigInteger;import java.util.*;public class Main {public static void main(String[] args) {        Scanner scanf=new Scanner(System.in);        BigInteger a,b,c;        int i,n;        while(scanf.hasNext())       {        BigInteger t=new BigInteger("1");        BigInteger t1=new BigInteger("1");        BigInteger ans=new BigInteger("0");        n=scanf.nextInt();        a=scanf.nextBigInteger();        for(i=1;i<=n;i++)        {        t=t.multiply(a);        t1=t.multiply(BigInteger.valueOf(i));        ans=ans.add(t1);        }        System.out.println(ans);       }    }}


0 0
原创粉丝点击