Problem Type : Number Theory
import java.math.*;
import java.util.Scanner;
/**
*
* @author Tarequzzaman Khan
*/
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args){
// TODO Auto-generated method stub
BigInteger tem1;
int a,b,t;
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
t=sc.nextInt();
a=sc.nextInt();
b=sc.nextInt();
if(t==1)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
if(a==b)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) 1");
continue;
}
if(a%b!=0||a<b)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
if( (a - b) * Math.log10(t) > 99)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
tem1=((BigInteger.valueOf(t)).pow(a)).subtract(BigInteger.ONE).divide(((BigInteger.valueOf(t)).pow(b)).subtract(BigInteger.ONE));
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) "+tem1);
}
}
}
import java.math.*;
import java.util.Scanner;
/**
*
* @author Tarequzzaman Khan
*/
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args){
// TODO Auto-generated method stub
BigInteger tem1;
int a,b,t;
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
t=sc.nextInt();
a=sc.nextInt();
b=sc.nextInt();
if(t==1)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
if(a==b)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) 1");
continue;
}
if(a%b!=0||a<b)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
if( (a - b) * Math.log10(t) > 99)
{
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) is not an integer with less than 100 digits.");
continue;
}
tem1=((BigInteger.valueOf(t)).pow(a)).subtract(BigInteger.ONE).divide(((BigInteger.valueOf(t)).pow(b)).subtract(BigInteger.ONE));
System.out.println("("+t+"^"+a+"-1)/("+t+"^"+b+"-1) "+tem1);
}
}
}
No comments:
Post a Comment