HDU4762 Cut the Cake

HDU4762 Cut the Cake

思路:公式:n/m(n-1)

//package acm;

import java.awt.Container;
import java.awt.geom.AffineTransform;
import java.math.*;
import java.util.*;

import javax.swing.tree.TreeNode;

import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID; 

public class Main
{    
    public static BigInteger gcd(BigInteger a,BigInteger b) {
        if(b.equals(BigInteger.ZERO)) {
            return a;
        }
        else {
            return gcd(b, a.mod(b));
        }
    }
    public static void main(String[] args) 
    {
        Scanner cin = new Scanner(System.in);
        int t = cin.nextInt();
        for(int cas = 0; cas < t; cas++)
        {
            BigInteger m = cin.nextBigInteger();
            int n = cin.nextInt();
            m = m.pow(n - 1);
            BigInteger tn = BigInteger.valueOf(n);
            BigInteger tt = gcd(tn, m);
            tn = tn.divide(tt);
            m = m.divide(tt);
            System.out.println(tn + "/" + m);
        }
        cin.close();
    }
}
View Code

 

posted on 2018-10-03 09:50  solvit  阅读(142)  评论(0编辑  收藏  举报

导航