結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
kyuridenamida
|
| 提出日時 | 2016-02-11 08:00:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 787 bytes |
| コンパイル時間 | 1,503 ms |
| コンパイル使用メモリ | 160,640 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:15:28 |
| 合計ジャッジ時間 | 2,350 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int,int> Pii;
typedef vector<Pii> VPii;
int main(){
long long A,B;
cin >> A >> B;
long long G = __gcd(A,B);
A /= G;
B /= G;
if( A % B == 0 ){
long long T = A / B;
while( T % 10 == 0 ) T /= 10;
cout << T % 10 << endl;
return 0;
}else{
A %= B;
set<long long> used;
__int128 P = A;
__int128 Q = B;
int ans = 0;
for(int i = 0 ; P && i < 1000 ; i++){
if( i == 999 ){
cout << -1 << endl;
return 0;
}
P = P * 10;
ans = P / Q;
P %= Q;
}
cout << ans << endl;
}
}
kyuridenamida