/*
ID: BryatnMark
LANG: JAVA
TASK: AC
*/
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.main(in, out);
out.close();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
String next() {
if (!hasNext())
throw new RuntimeException();
return tokenizer.nextToken();
}
boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
return false;
}
return true;
}
long nextLong() {
return Long.parseLong(next());
}
int nextInt() {
return Integer.parseInt(next());
}
}
class Task {
BigInteger one = BigInteger.ONE;
BigInteger zero = BigInteger.ZERO;
BigInteger[] f = new BigInteger[20];
BigInteger p, q, d;
int cnt = 0;
PrintStream cout = System.out;
BigInteger LCM(BigInteger a,BigInteger b)
{
BigInteger d=a.gcd(b);
return a.multiply(b).divide(d);
}
void dfs(int x, boolean plus, BigInteger mul) {
if (x < 0) {
if (plus)
p = p.add(q.divide(mul));
else
p = p.subtract(q.divide(mul));
return;
}
dfs(x-1,!plus,LCM(mul,f[x]));
dfs(x-1,plus,mul);
}
void main(InputReader in, PrintWriter out) throws Exception {
int n, i, k;
n = in.nextInt();
d = q = one;
p = zero;
for (i = 0; i < n; ++i) {
k = in.nextInt();
f[i] = BigInteger.valueOf(k);
d = q.gcd(f[i]);
q = q.multiply(f[i]).divide(d);
}
dfs(n-1,false,one);
p=p.add(q);
d=p.gcd(q);
p=p.divide(d);
q=q.divide(d);
out.println(p);
out.println(q);
}
}
POJ 2103 Jackpot
最新推荐文章于 2017-06-17 20:33:20 发布