結果
問題 | No.2358 xy+yz+zx=N |
ユーザー |
![]() |
提出日時 | 2023-06-26 14:03:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 298 ms / 2,000 ms |
コード長 | 2,888 bytes |
コンパイル時間 | 5,083 ms |
コンパイル使用メモリ | 95,576 KB |
実行使用メモリ | 62,488 KB |
最終ジャッジ日時 | 2024-07-03 09:10:32 |
合計ジャッジ時間 | 6,459 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
import java.io.*;import java.util.*;import java.util.stream.*;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner();int n = sc.nextInt();HashSet<Answer> ans = new HashSet<>();for (int i = 0; i * i * 3 <= n; i++) {for (int j = Math.max(1, i); i * j * 2 + j * j <= n && (n - i * j) / (i + j) >= j; j++) {if ((n - i * j) % (i + j) == 0) {int k = (n - i * j) / (i + j);ans.add(new Answer(i, j, k));ans.add(new Answer(i, k, j));ans.add(new Answer(j, i, k));ans.add(new Answer(j, k, i));ans.add(new Answer(k, i, j));ans.add(new Answer(k, j, i));}}}System.out.println(ans.size());StringBuilder sb = new StringBuilder();for (Answer x : ans) {sb.append(x).append("\n");}System.out.print(sb);}static class Answer {int a;int b;int c;public Answer(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}public int hashCode() {return a + b + c;}public boolean equals(Object o) {Answer x = (Answer)o;return a == x.a && b == x.b && c == x.c;}public String toString() {return new StringBuilder().append(a).append(" ").append(b).append(" ").append(c).toString();}}}class Utilities {static String arrayToLineString(Object[] arr) {return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));}static String arrayToLineString(int[] arr) {return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));}}class Scanner {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer("");StringBuilder sb = new StringBuilder();public Scanner() throws Exception {}public int nextInt() throws Exception {return Integer.parseInt(next());}public long nextLong() throws Exception {return Long.parseLong(next());}public double nextDouble() throws Exception {return Double.parseDouble(next());}public int[] nextIntArray() throws Exception {return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();}public String next() throws Exception {while (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}return st.nextToken();}}