/*
大数的加减运算不同于普通整数的加减乘除运算
加—— a+b: a=a.add(b);
减—— a-b: a=a.subtract(b);
乘—— a*b: a=a.multiply(b);
除—— a/b: a=a.divide(b);
求余—a%b: a=a.mod(b);
转换—a=b: b=BigInteger.valueOf(a);
比较 if (ans.compareTo(x) == 0)//比较
System.out.println("相等");
System.out.println("a + b = "+ans_add); // 这里的‘+’ (第二个) 是连接的意思
*/
import java.util.*;
import java.math.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int T; //声明int
T = cin.nextInt();//读入int
while((T--) != 0)
{
int n;
n = cin.nextInt();
BigInteger p = new BigInteger("1"); //大数
for(int i = 1;i <= n;i++)
{
Integer ii = new Integer(i);//转化为类
BigInteger iii = new BigInteger(ii.toString());
p = p.multiply(iii);
}
BigInteger ans = new BigInteger("0");
for(int i = 1;i <= n;i++)
{
Integer ii = new Integer(i);
BigInteger iii = new BigInteger(ii.toString());
ans = ans.add(p.divide(iii));
}
System.out.print(ans);
System.out.println(".0");
}
}
import java.util.*;
import java.math.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int T; //声明int
T = cin.nextInt();//读入int
int ko = 1;
while((T--) != 0)
{
int n;
n = cin.nextInt();
BigInteger m;
m = cin.nextBigInteger();
BigInteger a[] = new BigInteger[20005];
int top = 1;
int f = 0;
for(int i = 1;i <= n;i++)
{
a[top] = cin.nextBigInteger();
if(i==1||a[i].equals(a[i-1]) == false)
{
top++;
f = i;
}
}
if(f == n) top--;
a[0] = new BigInteger("100000000006");
a[top+1] = new BigInteger("0");
BigInteger num = new BigInteger("0");
BigInteger modd = new BigInteger("1000000007");
for(int i = 1;i <= top;i++)
{
if(a[i].compareTo(a[i-1])<0&&a[i].compareTo(a[i+1])<0)
{
num = m.divide(a[i]);
m = m.mod(a[i]);
}
if(a[i].compareTo(a[i-1])>0&&a[i].compareTo(a[i+1])>0)
{
m = m.add(num.multiply(a[i]));
num = new BigInteger("0");
}
}
m = m.mod(modd);
System.out.print("Case #"+ko+": ");
ko++;
System.out.println(m);
}
}
}
}
java大数高精度
最新推荐文章于 2023-05-08 15:56:56 发布