2018年第九届蓝桥杯省赛 Java A 组真题
第一题
![截屏2021-04-02 15.13.08](https://tva1.sinaimg.cn/large/008eGmZEgy1gpbd1dq9kuj313q0siac9.jpg)
import java.util.Calendar;
public class Q1 {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2000);
// 月份从 0 开始
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
int cnt = 1;
while (cal.get(Calendar.MONTH) != 4 || cal.get(Calendar.DAY_OF_MONTH) != 4) {
cal.add(Calendar.DAY_OF_MONTH, 1);
cnt++;
}
System.out.println(cnt);
}
}
答案:125
第二题
public class Q2 {
static int r = 1000;
public static void main(String[] args) {
int ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= r; j++) {
if (i * i + j * j <= r * r)
ans++;
}
}
System.out.println(ans * 4);
}
}
答案:3137548
第三题
![截屏2021-04-02 15.21.33](https://tva1.sinaimg.cn/large/008eGmZEgy1gpbczu1coqj318j0u0q6n.jpg)
import java.math.BigInteger;
public class Q3 {
public static void main(String[] args) {
BigInteger[] ans = pow(new BigInteger("2"), new BigInteger("3"), 123456);
System.out.println(ans[0] + " " + ans[1] + "i");
}
static BigInteger[] pow(BigInteger x, BigInteger y, int n) {
if (n == 0) return new BigInteger[] {
new BigInteger("1"), new BigInteger("0")};
if (n == 1) return new BigInteger[] {
x, y};
if (n % 2 != 0) {
BigInteger[] t = pow(x, y, n - 1)