結果
| 問題 |
No.413 +5,000,000pts
|
| ユーザー |
|
| 提出日時 | 2016-06-06 21:19:41 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 537 ms / 5,000 ms |
| コード長 | 1,943 bytes |
| コンパイル時間 | 2,257 ms |
| コンパイル使用メモリ | 82,012 KB |
| 実行使用メモリ | 64,136 KB |
| 最終ジャッジ日時 | 2024-10-12 02:25:14 |
| 合計ジャッジ時間 | 3,630 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
ソースコード
package yukicoder;
import java.math.BigDecimal;
public class Main{
public static void main(String[] args) {
new Main().solve();
}
void solve() {
int count = 0;
for (long i = 1_000_000_000L; i >= 1; i--) {
long d = i * (i + 1) - 1;
if (d <= 1_000_000_000_000_000_000L) {
while (!iscorrect(d)) {
System.out.println(d);
d--;
count++;
if (count == 100000)
return;
}
}
}
}
boolean iscorrect(long d) {
if(d>1_000_000_000_000_000_000L){
System.out.println("dが範囲外");
System.exit(0);
}
long ans = calc(d);
if (ans * ans + ans <= d && (ans + 1) * (ans + 1) + (ans + 1) > d) {
return true;
} else
return false;
}
long calc(long d) {
return (long) ((-1 + Math.sqrt(1 + 4 * d)) / 2.0);
}
double calc_ori(long d) {
return (-1 + Math.sqrt(1 + 4 * d)) / 2.0;
}
BigDecimal calc_ori_ex(long d) {
return BigDecimal.valueOf(-1).add(sqrt(BigDecimal.valueOf(4 * d + 1), 100)).divide(BigDecimal.valueOf(2));
}
void show(long d) {
System.out.println("参加者の示すtの値" + calc(d));
System.out.println("t*t+t " + (calc(d) * calc(d) + calc(d)));
System.out.println("(t+1)(t+1)+(t+1)" + ((calc(d) + 1) * (calc(d) + 1) + (calc(d) + 1)));
System.out.println("d " + d);
System.out.println("二次方程式を解いた時のtの値(参加者の)" + calc_ori(d));
System.out.println("二次方程式を解いた時のt(参加者の)でのt*t+t" + (calc_ori(d) * calc_ori(d) + calc_ori(d)));
System.out.println("二次方程式を解いた時のtの値(精度を上げた)" + calc_ori_ex(d));
}
// scaleは桁数。
public static BigDecimal sqrt(BigDecimal a, int scale) {
BigDecimal x = a;
for (int i = 0; i < 10000; i++) {
// x=x-(x*x-a)/(2*x)
x = x.subtract((x.multiply(x).subtract(a)).divide((x.multiply(BigDecimal.valueOf(2.0))), scale,
BigDecimal.ROUND_HALF_EVEN));
}
return x;
}
}