結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2015-06-08 23:13:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,385 bytes |
| コンパイル時間 | 701 ms |
| コンパイル使用メモリ | 89,380 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-07-06 14:55:05 |
| 合計ジャッジ時間 | 7,319 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 TLE * 1 -- * 23 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
map<ull,int> factorize(ull x){
map<ull,int> ret;
ull d, q;
while(x>=4 && x%2==0){ret[2]++; x/=2;}
d = 3; q = x/d;
while(q>=d){
if(x%d==0){ ret[d]++; x=q; }else{ d+=2; }
q=x/d;
}
ret[x]++;
return ret;
}
int main(){
ull N, M;
cin >> N;
cin >> M;
map<ull,int> res1 = factorize(N);
map<ull,int> res2 = factorize(M);
if(res2.count(2) == 0 && res2.count(5) == 0){
cout << -1 << endl;
return 0;
}
FOR(it,res2){
while(res1[it->first] && res2[it->first]>0){
N/=it->first;
M/=it->first;
res1[it->first]--;
res2[it->first]--;
}
}
ull ret = 0;
while(N<M) N *= 10ULL;
while(true){
if(N==0){
while(ret>=10 && ret%10==0) ret=ret/10ULL;
ret = ret%10;
cout << ret << endl;
return 0;
}
ret = N/M;
N %= M;
N *= 10LL;
}
return 0;
}
どらら