求 n/1+n/2+...n/n 用最简分数表示
/*
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;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public 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;
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public BigInteger nextBigInteger(){
return new BigInteger(next());
}
}
class Task {
BigInteger zero=BigInteger.ZERO;
BigInteger p,x,y,d,r,one=BigInteger.ONE;
BigInteger[] f=new BigInteger[40];
void main(InputReader in, PrintWriter out) throws Exception {
f[0]=one;
int i,n;
for(i=1;i<35;++i)
{
f[i]=f[i-1].multiply(BigInteger.valueOf(i));
}
while(in.hasNext())
{
n=in.nextInt();
x=zero;
for(i=1;i<=n;++i)
{
x=x.add(f[n].divide(BigInteger.valueOf(i)));
}
x=x.multiply(BigInteger.valueOf(n));
y=f[n];
r=x.mod(y);
d=x.gcd(y);
//out.println(x+" "+y);
x=x.divide(d);
y=y.divide(d);
p=x.divide(y);
if(r.equals(zero))
{
out.println(p);
continue;
}
x=x.subtract(p.multiply(y));
int len,L;
len=0;
String a,b,c;
a=p.toString();
b=x.toString();
c=y.toString();
L=Math.max(b.length(),c.length());
if(p.compareTo(zero)>0)
{
len=a.length()+1;
a=a+" ";
}
else
{
a="";
}
for(i=0;i<len;++i) out.print(" "); out.println(b);
out.print(a);
for(i=0;i<L;++i) out.print("-"); out.println("");
for(i=0;i<len;++i) out.print(" "); out.println(c);
}
}
}