-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.java
More file actions
64 lines (63 loc) · 2.11 KB
/
Copy pathexample.java
File metadata and controls
64 lines (63 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
while (in.hasNextInt())
{
int t = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
System.out.print("(" + t + "^" + a + "-1)/");
System.out.print("(" + t + "^" + b + "-1) ");
if (t == 1)
{
System.out.println("is not an integer with less than 100 digits.");
}
else if (a % b != 0)
{
System.out.println("is not an integer with less than 100 digits.");
}
else if (a == b)
{
System.out.println("1");
}
else
{
BigInteger ans = new BigInteger("1", 10);
BigInteger tmp = new BigInteger("1", 10);
BigInteger fff = new BigInteger(Integer.toString(t), 10);
BigInteger gxx = new BigInteger("1", 10);
String s = "";
for (int i = 0; i < 100; ++i)
s += "9";
BigInteger lim = new BigInteger(s, 10);
for (int i = 0; i < b; ++i)
{
gxx = gxx.multiply(fff);
if (gxx.compareTo(lim) > 0) break;
}
//System.out.println(gxx);
if (gxx.compareTo(lim) > 0)
{
System.out.println("is not an integer with less than 100 digits.");
continue;
}
int tt = b;
b += tt;
while (b <= a)
{
tmp = tmp.multiply(gxx);
ans = ans.add(tmp);
if (b == a) break;
b += tt;
}
if (ans.compareTo(lim) > 0)
System.out.println("is not an integer with less than 100 digits.");
else
System.out.println(ans);
}
}
}
}