第十四届蓝桥杯三月真题刷题训练——第 2 天
题目1:奇数倍数
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws Exception {
// for (int i = 2; i <= 100; i++) {
// long num = 2019 * i;
// boolean flag = true;
// while (num > 0) {
// int t = (int)(num % 10);
// if ((t & 1) == 0) {
// flag = false;
// break;
// }
// num /= 10;
// }
// if (flag) {
// out.print(2019 * i);
// break;
// }
// }
out.println("139311");
out.flush();
in.close();
}
}
题目2:求值
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[] args) throws Exception {
// for (int i = 2; i < 1000000; i++) {
// int cnt = 0, end = (int)Math.sqrt(i);
// for (int j = 1; j <= end; j++) {
// if (i % j == 0) {
// cnt += 2;
// if (i == j) cnt--;
// }
// }
// if (cnt == 100) {
// out.println(i);
// break;
// }
// }
out.println("45360");
out.flush();
in.close();
}
}
题目3:求和
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static int N = (int)2e5 + 10, n;
static int[] arr = new int[N], pre = new int[N];
public static void main(String[] args) throws Exception {
n = Integer.parseInt(in.readLine());
String[] s = in.readLine().split(" ");
for (int i = 1; i <= n; i++) {
arr[i] = Integer.parseInt(s[i - 1]);
pre[i] = arr[i] + pre[i - 1];
}
long ans = 0L;
for (int i = 1; i <= n; i++) {
ans += (long)arr[i] * (pre[n] - pre[i]);
}
out.println(ans);
out.flush();
in.close();
}
}
题目4:数位排序
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static int N = (int)1e6 + 10, n, m;
static Integer[] a = new Integer[N];
public static int helper(int n, int m) {
for (int i = 0; i < n; i++) a[i] = i + 1;
Arrays.sort(a, 0, n, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int a = 0, b = 0, n1 = o1, n2 = o2;
while (n1 > 0) {
a += n1 % 10;
n1 /= 10;
}
while (n2 > 0) {
b += n2 % 10;
n2 /= 10;
}
if (a > b) {
return 1;
} else if (a < b) {
return -1;
}
return o1 - o2;
}
});
return a[m - 1];
}
public static void main(String[] args) throws Exception {
n = Integer.parseInt(in.readLine());
m = Integer.parseInt(in.readLine());
out.println(helper(n, m));
out.flush();
in.close();
}
}