# Java 第十四届蓝桥杯三月真题刷题训练——第 2 天

Feishi11 2023-03-05 14:43:14

# 第一题：奇数倍数

``````
public class Main{
public static void main(String[] args) {
int n = 2019;
for (int i = 2; i <= Integer.MAX_VALUE; i++) {
long tmp = (long) n * i;
if (check(tmp)) {
System.out.println(tmp);
break;
}
}
}

static boolean check(long tmp) {
while (tmp > 0) {
long sum = tmp % 10;
tmp /= 10;
if ((sum & 1) != 1) {
return false;
}
}
return true;
}
}
``````

# 第二题：求值

``````public class Main{
public static void main(String[] args) {
for (int k = 100; k <= Integer.MAX_VALUE; k++) {
int max = 1;
int n = k;
for (int i = 2; i <= n / i; i++) {
int count = 0;
while (n % i == 0) {
count++;
n /= i;
}
max *= (count + 1);
}
if (n > 1) {
max <<= 1;
}
if (max == 100) {
System.out.println(k);
return;
}
}
}
}
``````

# 第三题：求和

``````
import java.io.IOException;

public class Main {

public static void main(String[] args) throws IOException {
long ans = 0, ans1 = 0;
for (int i = 1; i <= n; i++) {
int x = Integer.parseInt(s[i - 1]);
ans += x * x;
ans1 += x;
}
System.out.println((ans1 * ans1 - ans) / 2);
}
}``````

# 第四题：数位排序

``````
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

public class Main{

public static void main(String[] args) throws IOException {
Integer[] a = new Integer[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = i;
}
Arrays.sort(a, 1, n + 1, (o1, o2) -> {
int tmp = get(o1);
int tmp2 = get(o2);
if (tmp > tmp2) {
return 1;
} else if (tmp < tmp2) {
return -1;
}
return o1 - o2;

});
System.out.println(a[m]);
}

public static int get(int x) {
int sum = 0;
while (x > 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
}
``````

...全文
7 回复 打赏 收藏 举报

4.2w+

2023-03-05 14:43

刷题！