結果
| 問題 |
No.2358 xy+yz+zx=N
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-07-31 11:00:09 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 364 ms / 2,000 ms |
| コード長 | 2,966 bytes |
| コンパイル時間 | 2,526 ms |
| コンパイル使用メモリ | 84,416 KB |
| 実行使用メモリ | 61,540 KB |
| 最終ジャッジ日時 | 2024-07-31 11:00:17 |
| 合計ジャッジ時間 | 6,638 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
List<Answer> ans = new ArrayList<>();
int count = 0;
for (int i = 0; i <= Math.sqrt(n); i++) {
for (int j = i; j <= Math.sqrt(n); j++) {
if (i == 0 && j == 0) {
continue;
}
if ((n - i * j) % (i + j) == 0 && (n - i * j) / (i + j) >= j) {
Answer current = new Answer(i, j, (n - i * j) / (i + j));
count += current.size();
ans.add(current);
}
}
}
System.out.println(count);
System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
}
static class Answer {
Set<Three> threes = new HashSet<>();
public Answer(int a, int b, int c) {
threes.add(new Three(a, b, c));
threes.add(new Three(a, c, b));
threes.add(new Three(b, a, c));
threes.add(new Three(b, c, a));
threes.add(new Three(c, a, b));
threes.add(new Three(c, b, a));
}
public int size() {
return threes.size();
}
public String toString() {
return threes.stream().map(x -> x.toString()).collect(Collectors.joining("\n"));
}
}
static class Three {
int a;
int b;
int c;
public Three(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int hashCode() {
return Objects.hash(a, b, c);
}
public boolean equals(Object o) {
Three x = (Three)o;
return a == x.a && b == x.b && c == x.c;
}
public String toString() {
return a + " " + b + " " + c;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten