This commit is contained in:
2025-12-28 21:05:06 +08:00
parent 5d09b15326
commit bdaedc135e
46 changed files with 485 additions and 38 deletions
@@ -0,0 +1,51 @@
import java.util.*;
import java.util.regex.*;
public class P2895 {
static String normalize(String s) {
boolean neg = s.startsWith("-");
String t = neg ? s.substring(1) : s;
int i = 0;
while (i < t.length() - 1 && t.charAt(i) == '0') i++;
t = t.substring(i);
if (t.equals("0")) neg = false;
return neg ? ("-" + t) : t;
}
static int cmpNum(String a, String b) {
boolean na = a.startsWith("-");
boolean nb = b.startsWith("-");
if (na != nb) return na ? -1 : 1;
String aa = na ? a.substring(1) : a;
String bb = nb ? b.substring(1) : b;
if (!na) {
if (aa.length() != bb.length()) return aa.length() < bb.length() ? -1 : 1;
int c = aa.compareTo(bb);
return c < 0 ? -1 : (c > 0 ? 1 : 0);
} else {
if (aa.length() != bb.length()) return aa.length() > bb.length() ? -1 : 1;
int c = aa.compareTo(bb);
return c > 0 ? -1 : (c < 0 ? 1 : 0);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
StringBuilder input = new StringBuilder();
while (in.hasNextLine()) {
if (input.length() > 0) input.append('\n');
input.append(in.nextLine());
}
Matcher m = Pattern.compile("-?\\d+").matcher(input.toString());
List<String> nums = new ArrayList<>();
while (m.find()) nums.add(normalize(m.group()));
nums.sort(P2895::cmpNum);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nums.size(); i++) {
if (i > 0) sb.append(',');
sb.append(nums.get(i));
}
System.out.println(sb.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

@@ -0,0 +1,27 @@
import java.util.*;
public class P2966 {
static long maxPrimeFactor(long n) {
if (n <= 1) return 1;
long max = -1;
while ((n & 1) == 0) { max = 2; n >>= 1; }
for (long i = 3; i * i <= n; i += 2) {
while (n % i == 0) { max = i; n /= i; }
}
if (n > 1) max = n;
return max;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
List<Long> nums = new ArrayList<>();
while (in.hasNextLong()) nums.add(in.nextLong());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nums.size(); i++) {
if (i > 0) sb.append(',');
sb.append(maxPrimeFactor(nums.get(i)));
}
System.out.println(sb.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

@@ -0,0 +1,36 @@
import java.util.*;
public class P2967 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
if (!in.hasNextLong()) { in.close(); return; }
long n = in.nextLong();
boolean neg = n < 0;
if (neg) n = -n;
StringBuilder sb = new StringBuilder();
if (neg) sb.append('-');
if (n == 1) {
sb.append('1');
System.out.println(sb.toString());
in.close();
return;
}
long p = 2;
boolean first = true;
while (n > 1 && p * p <= n) {
while (n % p == 0) {
if (!first) sb.append('*');
sb.append(p);
first = false;
n /= p;
}
p = (p == 2) ? 3 : (p + 2);
}
if (n > 1) {
if (!first) sb.append('*');
sb.append(n);
}
System.out.println(sb.toString());
in.close();
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB