4.3w+
社区成员
奇数倍数
public class Main {
public static void main(String[] args) {
for (int i = 2019; ; i += 2019) {
if (check(i)) {
System.out.println(i);
break;
}
}
}
static boolean check(int i) {
while (i > 0) {
if (i%2 == 0) return false;
i /= 10;
}
return true;
}
}
求值
public class Main {
public static void main(String[] args) {
for (int i = 2; ; i++) {
int ans = 0;
for (int j = 1; j < i / j; j++) {
if (i % j == 0) ans++;
}
if (ans == 50) {
System.out.println(i);
return;
}
}
}
}
求和
import java.util.Scanner;
public class Main {
static int N = 200010;
static long[] a = new long[N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
long ans = 0;//保存结果
long sum = 0;//保存前i-1项的和
for (int i = 1; i <= n; i++) {
ans += a[i] * sum;
sum += a[i];
}
System.out.println(ans);
}
}
数位排序
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
//要自定义排序的话 要用 Integer[]
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) a[i] = i + 1;
//自定义排序
Arrays.sort(a, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int a = check(o1);
int b = check(o2);
if (a != b) return a - b;
else return o1 - o2;
}
});
System.out.println(a[m - 1]);
}
//求数位和
private static int check(Integer x) {
int res = 0;
while (x != 0) {
res += x % 10;
x /= 10;
}
return res;
}
}