結果

問題 No.25 有限小数
ユーザー どららどらら
提出日時 2015-06-08 22:00:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,177 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-20 19:59:26
合計ジャッジ時間 7,257 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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;

ull gcd(ull a, ull b){return (b==0?a:gcd(b,a%b));}
ull lcm(ull a, ull b){return a/gcd(a,b)*b;}
ull lambda(ull n){
  ull ret=1;
  if(n%8==0) n/=2;
  for(ull d=2; d<=n; d++){
    if(n%d==0){
      ull y=d-1;
      n/=d;
      while(n%d==0){
        n/=d;
        y*=d;
      }
      ret=lcm(ret, y);
    }
  }
  return ret;
}



int main(){
  ull N, M;
  cin >> N;
  cin >> M;
  
  ll keta = lambda(M) + 1;
  ll ret = 0;
  while(N<M) N *= 10LL;
  while(keta>=0){
    if(N==0){
      cout << ret << endl;
      return 0;
    }
    ret = N/M;
    if(ret>=10) ret = ret%10;
    N %= M;
    N *= 10LL;
    --keta;
  }
  cout << -1 << endl;
  
  return 0;
}
0