📢📢📢哈喽哈喽各位好 前两天甲流了 身体抱恙 没能及时更新,大家一定要注意保暖不要生病,发烧太难受了😭😭😭
🍒🍒🍒找素数🍒🍒🍒
📋问题描述

❓思路分享
🍒就是用欧拉筛去筛出从2开始的质数,每筛出一个统计数的变量就+1,加到100002时的i就是第100002个质数
📗参考代码
public class Main {
public static void main(String[] args) {
int ans = 0;
int i = 2;
for (; i < Integer.MAX_VALUE; i++) {
if (check(i)) ans++;
if (ans == 100002) break;
}
System.out.println(i);
}
static boolean check(int n) {
for (int i = 2; i <= n / i; i++) {
if (n % i == 0) return false;
}
return true;
}
}
🍎🍎🍎图书排列🍎🍎🍎
📋问题描述

❓思路分享
这道题看了题目没有一点思路哈哈 ,看了归辞同学的代码才知道应该是DFS + 回溯。给大家分享一下吧。
📗参考代码
import java.util.*;
public class 图书排列 {
static int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
static int count_num = 0;
public static void DFS(int i, boolean root[], int x[]) {
if (i >= 10) {
count_num++;
return;
} else {
for (int j = 0; j < 10; j++) {
if (i == 0 || (Math.abs(arr[j] - x[i - 1]) != 1 && !root[j])) {
x[i] = arr[j];
root[j] = true;
DFS(i + 1, root, x);
x[i] = 0;
root[j] = false;
}
}
}
}
public static void main(String[] args) {
boolean[] root = new boolean[10];
int[] x = new int[10];
DFS(0, root, x);
System.out.print(count_num);
}
}
⛅⛅⛅日志统计⛅⛅⛅