Problem Type : Number Theory
import java.math.BigInteger;
import java.util.Scanner;
/**
*
* @author Tarequzzaman Khan
*/
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,a,n;
BigInteger sum,A;
while(sc.hasNext())
{
n= sc.nextInt();
a=sc.nextInt();
sum = new BigInteger("0");
A = BigInteger.valueOf(a);
for(i=1; i<=n; i++)
{
sum = sum.add(BigInteger.valueOf(i).multiply(A.pow(i)));
}
System.out.println(sum);
}
}
}
import java.math.BigInteger;
import java.util.Scanner;
/**
*
* @author Tarequzzaman Khan
*/
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i,a,n;
BigInteger sum,A;
while(sc.hasNext())
{
n= sc.nextInt();
a=sc.nextInt();
sum = new BigInteger("0");
A = BigInteger.valueOf(a);
for(i=1; i<=n; i++)
{
sum = sum.add(BigInteger.valueOf(i).multiply(A.pow(i)));
}
System.out.println(sum);
}
}
}
No comments:
Post a Comment