码迷,mamicode.com
首页 > 其他好文 > 详细

HDU4762 Cut the Cake

时间:2018-10-03 20:09:57      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:nsf   main   lan   color   pen   cas   ret   family   awt   

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

 

HDU4762 Cut the Cake

标签:nsf   main   lan   color   pen   cas   ret   family   awt   

原文地址:https://www.cnblogs.com/solvit/p/9739224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!