hdoj 4762 Cut the Cake

题意很简单就不说了。

解题的关键就是这个公式

answer=n/(m^(n-1));

要用到大数的乘法。然后java水过。

import java.util.*;
import java.math.*;

public class Main {
	public static BigInteger gcd (BigInteger a, BigInteger b) {
		if (a.mod(b).equals(BigInteger.valueOf(0)))
			return b;
		return gcd(b, a.mod(b));
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		BigInteger a, b, c;
		int n, m;
		while (t--!= 0) {
			m = cin.nextInt();
			n = cin.nextInt();
			a = BigInteger.valueOf(1);
			for (int i = 1; i < n; i++)
				a = a.multiply(BigInteger.valueOf(m));
			b = BigInteger.valueOf(n);
			c = gcd(a, b);
			System.out.println(b.divide(c) + "/" + a.divide(c));
		}
		cin.close();
	}
}


posted @ 2013-10-22 19:52  xindoo  阅读(141)  评论(0编辑  收藏  举报