hdu 4762 公式 java

n/(n)^(m-1)

 1 import java.io.*;
 2 import java.math.*;
 3 import java.util.*;
 4
 5 public class Main {
 6     static BigInteger gcd(BigInteger a,BigInteger b)
 7     {
 8         if(b.equals(BigInteger.ZERO))return a;
 9         else return gcd(b,a.mod(b));
10     }
11     public static void main(String arg[])
12     {
13         int T;
14         int n,m;
15         Scanner cin = new Scanner(System.in);
16         T = cin.nextInt();
17         while( T > 0 )
18         {
19             m = cin.nextInt();
20             n = cin.nextInt();
21             BigInteger tmp1 = BigInteger.valueOf(n);
22             BigInteger tmp2 = BigInteger.valueOf(m).pow(n-1);
23             BigInteger tt = gcd(tmp1,tmp2);
24             tmp1 = tmp1.divide(tt);
25             tmp2 = tmp2.divide(tt);
26             System.out.println(tmp1+"/"+tmp2);
27             T--;
28         }
29     }
30 }
时间: 2024-12-29 23:32:28

hdu 4762 公式 java的相关文章

hdu4927 Series 1(组合+公式 Java大数高精度运算)

题目链接: Series 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 423    Accepted Submission(s): 146 Problem Description Let A be an integral series {A1, A2, . . . , An}. The zero-order series o

判断表达式是否为命题公式java编写

1 import java.util.Scanner; 2 3 public class express { 4 public static void main(String[] args) throws Exception{ 5 System.out.println("请输入表达式:"); 6 Scanner exp = new Scanner(System.in); 7 String expressNew = exp.nextLine(); 8 9 boolean answer =

HDU - 1042 - N! - JAVA

http://acm.hdu.edu.cn/showproblem.php?pid=1042 大数嘛,直接用JAVA. 为什么要开64路?好像我觉得会快一点--其实并没有快-- import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while

hdu 2023 简单java 水过~~~

Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. Input 输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数.然后是n行数据,每行包括m个整数(即:考试分数). Output 对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数:第二行包含m个数据,表示m门课的平均成绩,结果保留

HDU Exponentiation 1063 Java大数题解

Exponentiation Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6973    Accepted Submission(s): 1975 Problem Description Problems involving the computation of exact values of very large magnitude

hdu 1042 N! java大数及判断文件末尾

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 73503    Accepted Submission(s): 21308 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in on

Hdu 4762 网络赛 高精度大数模板+概率

注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放,所以最后的概率为n/m^(n-1),最后通过大数模板搞定该题的化简. C++代码 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<iomanip> 5 #include

[ACM]HDU Problem 1000 + Java

//no package name //import when necessary import java.util.Scanner; //it has to be Main class public class Main { public static void main(String[] args){ Scanner input = new Scanner(System.in); //Wrong answer when using while(true) while(input.hasNex

[ACM]HDU Problem 1001 + Java

import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner input = new Scanner(System.in); while(input.hasNext()){ int n = input.nextInt(); int sum = 0; //暴力加合 for(int i=1; i<n+1; i++){ sum+=i; } System.out.println(