結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-07-30 20:13:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,841 bytes |
| コンパイル時間 | 597 ms |
| コンパイル使用メモリ | 72,956 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-17 22:38:07 |
| 合計ジャッジ時間 | 1,614 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 1 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;
#define mod 1000003
#define INF 10000000
#define LLINF 2000000000000000000LL
#define SIZE 10000
ll n,m;
ll gcd(ll a,ll b){
if(a==0)
return b;
return gcd(b%a,a);
}
int main(){
ll ans=0;
cin >> n >> m;
ll G = gcd(n,m);
n/=G;
m/=G;
if(m==1){
while(n%10==0) n/=10;
printf("%lld\n",n%10);
return 0;
}
ll M = m;
bool M2=false,M5=false;
while(M%2==0){ M/=2; M2=true;}
while(M%5==0){ M/=5; M5=true;}
if(M!=1){
puts("-1");
return 0;
}
if(m<(1LL<<55)){
while(n%m>0){
n%=m;
n*=10;
}
printf("%lld\n",n/m);
return 0;
}
if((M2 && M5) || m<(1LL<<55)){
m/=10;
while(n%m>0){
n%=m;
n*=10;
}
printf("%lld\n",n/m);
return 0;
}
if(M5){
m/=25;
while(n%m>0){
ans*=10;
ans+=n/m;
ans%=1000;
n%=m;
n*=10;
}
while(ans%25>0){
ans%=25;
ans*=10;
}
printf("%lld\n",(ans/25)%10);
}
if(M2){
m/=16;
while(n%m>0){
ans*=10;
ans+=n/m;
ans%=1000;
n%=m;
n*=10;
}
while(ans%16>0){
ans%=16;
ans*=10;
}
printf("%lld\n",(ans/16)%10);
}
return 0;
}
goodbaton