結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2015-06-09 02:15:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,250 bytes |
| コンパイル時間 | 668 ms |
| コンパイル使用メモリ | 79,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:11:06 |
| 合計ジャッジ時間 | 1,594 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#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;
ll mod_pow(ll x, ll n, ll mod){
ll res = 1;
while(n>0){
if(n&1) res = res*x%mod;
x = x*x%mod;
n >>= 1;
}
return res;
}
ull gcd(ull a, ull b){return (b==0?a:gcd(b,a%b));}
int main(){
ull N, M;
cin >> N;
cin >> M;
ull g = gcd(N,M);
N/=g;
M/=g;
int cnt2=0, cnt5=0;
while(M%2==0){
M/=2;
cnt2++;
}
while(M%5==0){
M/=5;
cnt5++;
}
if(M!=1){
cout << -1 << endl;
return 0;
}
while(N%10==0) N/=10;
N%=10;
int mx = max(cnt2, cnt5);
cnt2 = mx - cnt2;
cnt5 = mx - cnt5;
ull ret = N;
while(cnt2>0){
ret *= 2;
ret %= 10;
cnt2--;
}
while(cnt5>0){
ret *= 5;
ret %= 10;
cnt5--;
}
cout << ret << endl;
return 0;
}
どらら