結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-07-25 15:41:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,352 bytes |
| コンパイル時間 | 762 ms |
| コンパイル使用メモリ | 87,140 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:11:22 |
| 合計ジャッジ時間 | 1,526 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
LL gcd(LL a,LL b){
while( b != 0){
a = a % b;
swap(a,b);
}
return a;
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
//解説見た
LL N,M;
cin>>N>>M;
LL gcdNum = gcd(N,M);
N /= gcdNum;
M /= gcdNum;
if( M == 1){
while(N % 10 == 0){
N /= 10;
}
P(N%10);
return 0;
}
int count2=0;
int count5=0;
while( M%2 == 0){
M /= 2;
++count2;
}
while( M%5 == 0){
M /= 5;
++count5;
}
if( M != 1){
P(-1);
return 0;
}
while(N % 10 == 0){N /= 10;}
if( count2 < count5){
//count5-count2回2/2を掛ける
rep(i,count5-count2){
N *= 2;
while(N % 10 == 0){N /= 10;}
N = N % 1000;
}
}else{
rep(i,count2-count5){
N *= 5;
while(N % 10 == 0){N /= 10;}
N = N % 1000;
}
}
P(N%10);
return 0;
}
IL_msta