2140 星期计算
2140 星期计算
⭐️难度:中等
🌟考点:2022、思维、省赛
📖
📚
1️⃣法一:
同余定理,
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum = 1;
for (int i = 1; i <= 22; i++) {
// 同余定理
sum = sum * (20 % 7);
sum = sum % 7;
}
int ans = (6 + sum) % 7;
System.out.println(ans == 0 ? 7 : ans);
}
}
2️⃣法二:
用java自带高精度,
import java.math.BigInteger;
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 创建 BigInteger 对象表示 20
BigInteger p = BigInteger.valueOf(20);
// 计算 20 的 22 次方
BigInteger result = p.pow(22);
// 创建 BigInteger 对象表示 7
BigInteger modnum = BigInteger.valueOf(7);
// 对结果进行取模运算
BigInteger ans = result.mod(modnum);
int day = 6 + ans.intValue() % 7;
System.out.println(day == 0 ? 0 : day);
}
}
3️⃣法三:
利用电脑自带的计算机:
由此可见,填空题有时候有多种做法,考场上可以利用这些方法进行验证。