結果

問題 No.25 有限小数
ユーザー どららどらら
提出日時 2015-06-09 01:25:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,604 bytes
コンパイル時間 4,025 ms
コンパイル使用メモリ 85,508 KB
実行使用メモリ 7,608 KB
最終ジャッジ日時 2023-09-20 20:03:44
合計ジャッジ時間 14,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

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]>0 && res2[it->first]>0){
      N/=it->first;
      M/=it->first;
      res1[it->first]--;
      res2[it->first]--;
    }
  }

  FOR(it,res2){
    if(it->second == 0) continue;
    if(it->first != 2 && it->first != 5){
      cout << -1 << endl;
      return 0;
    }
  }
  
  int mx = max(res2[2],res2[5]);
  res1[2]+=mx;
  res1[5]+=mx;
  res1[2]-=res2[2];
  res1[5]-=res2[5];
  
  while(res1[2]>0 && res1[5]>0){
    res1[2]--;
    res1[5]--;
  }

  
  ull ret = 1;
  FOR(it,res1){
    rep(i,it->second){
      ret *= it->first;
      ret %= 10;
    }
  }
  cout << ret << endl;
  
  return 0;
}
0