-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.java
71 lines (63 loc) · 1.33 KB
/
lib.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.math.*;
final class Lib{
//素数かどうか判断
public static boolean isPrime(int num){
int sqrt = (int) Math.sqrt(num) + 1;
for (int i = 2; i < sqrt ; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
//桁数を返す(大数用)
public static BigInteger BigDigitNum(BigInteger f){
BigInteger bigTmp,bigSum,bigZero,big0ne;
bigTmp = new BigInteger("10");
bigSum = new BigInteger("0");
bigZero = new BigInteger("0");
big0ne = new BigInteger("1");
while(true){
bigSum = bigSum.add(big0ne);
f=f.divide(bigTmp);
if( f.equals(bigZero)){
break;
}
}
return bigSum;
}
///桁数を返す
public static int DigitNum(int f){
int sum=0;
while(true){
f = f/10;
sum++;
if( f==0){
return sum;
}
}
}
//最大公約数を返す(ユークリッドの互除法)
public static int gcd(int x,int y){
if(y == 0){
return x;
}else{
return gcd(y, x % y);
}
//System.out.println(y);
}
//最小公倍数を返す
public static int lcm(int x,int y){
return x*y/gcd(x,y);
}
//配列の中から最大値を求める
public static int MaxArr(int[] a){
int max=0;
for(int i =1 ; i < a.length; i++){
if(a[i] > a[max]){
max = i;
}
}
return a[max];
}
}