結果

問題 No.25 有限小数
ユーザー どららどらら
提出日時 2015-06-09 02:15:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,250 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 79,960 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-27 17:10:34
合計ジャッジ時間 1,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0