結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2017-11-11 10:31:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 2,313 ms / 5,000 ms |
| コード長 | 1,258 bytes |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 78,756 KB |
| 実行使用メモリ | 62,000 KB |
| 最終ジャッジ日時 | 2024-11-24 18:54:34 |
| 合計ジャッジ時間 | 21,504 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static long MOD = 1000000007;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger N = new BigInteger(sc.next());
BigInteger M = new BigInteger(sc.next());
BigInteger answer = BigInteger.ZERO;
HashSet<BigInteger> already = new HashSet<BigInteger>();
/*
* 嘘解法っぽいの投げたら通っちゃった...
* 実際、素因数を mod で篩うのを十分やれば
* 10 以外の因数が含まれているか分かっちゃうか
*/
boolean found = false;
for(int tt = 0; tt <= 100000; tt++){
answer = answer.multiply(BigInteger.TEN);
answer = answer.add(N.divide(M));
final BigInteger mod = N.mod(M);
if(mod.equals(BigInteger.ZERO)){
found = true;
break;
}
if(already.contains(mod)){
System.out.println(-1);
return;
}
already.add(mod);
N = mod.multiply(BigInteger.TEN);
}
if(!found){ System.out.println(-1); return; }
final String output = answer.toString().replace("0", "");
System.out.println(output.charAt(output.length() - 1));
}
}
uafr_cs