Submission #18262168
Source Code Expand
Copy
import java.io.*;import java.math.BigInteger;import java.util.Arrays;import java.util.StringTokenizer;public class Main {// 注意不要用Arrays.sort()// 注意Math.pow可能导致精度问题// 注意int溢出问题static class Task {public void solve(int testNumber, InputReader in, PrintWriter out) {long s = in.nextLong();long p = in.nextLong();BigInteger bigS = new BigInteger(String.valueOf(s));BigInteger bigP = new BigInteger(String.valueOf(p));BigInteger tmp = bigS.multiply(bigS).subtract(bigP.multiply(new BigInteger("4"))); // b^2 - 4ac
import java.io.*; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; public class Main { // 注意不要用Arrays.sort() // 注意Math.pow可能导致精度问题 // 注意int溢出问题 static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { long s = in.nextLong(); long p = in.nextLong(); BigInteger bigS = new BigInteger(String.valueOf(s)); BigInteger bigP = new BigInteger(String.valueOf(p)); BigInteger tmp = bigS.multiply(bigS).subtract(bigP.multiply(new BigInteger("4"))); // b^2 - 4ac BigInteger bigDelta = tmp.sqrt(); if (!bigDelta.multiply(bigDelta).equals(tmp)) { out.println("No"); return; } long delta = Long.parseLong(String.valueOf(bigDelta)); out.println(((s + delta) % 2 == 0 && (s - delta) % 2 == 0 && s - delta > 0) ? "Yes" : "No"); } } private static void sort(double[] arr) { Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void sortDesc(double[] arr) { Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[arr.length - i - 1]; } } private static void sort(int[] arr) { Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void sortDesc(int[] arr) { Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[arr.length - i - 1]; } } private static void sort(long[] arr) { Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void sortDesc(long[] arr) { Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[arr.length - i - 1]; } } private static void solve() { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task task = new Task(); task.solve(1, in, out); out.close(); } public static void main(String[] args) { new Thread(null, () -> solve(), "1", 1 << 26).start(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Sum and Product |
User | yuruiyin |
Language | Java (OpenJDK 11.0.6) |
Score | 300 |
Code Size | 4061 Byte |
Status | AC |
Exec Time | 91 ms |
Memory | 34304 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, sample_01.txt, sample_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
random_01.txt | AC | 91 ms | 34076 KB |
random_02.txt | AC | 86 ms | 34244 KB |
random_03.txt | AC | 82 ms | 34304 KB |
random_04.txt | AC | 76 ms | 33992 KB |
random_05.txt | AC | 82 ms | 33988 KB |
random_06.txt | AC | 77 ms | 33804 KB |
random_07.txt | AC | 85 ms | 34256 KB |
random_08.txt | AC | 78 ms | 34080 KB |
random_09.txt | AC | 83 ms | 34096 KB |
random_10.txt | AC | 81 ms | 34084 KB |
random_11.txt | AC | 82 ms | 34000 KB |
random_12.txt | AC | 80 ms | 34100 KB |
sample_01.txt | AC | 77 ms | 33788 KB |
sample_02.txt | AC | 87 ms | 34244 KB |