結果

問題 No.25 有限小数
ユーザー LayCurseLayCurse
提出日時 2014-11-07 10:37:30
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 159,520 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 21:06:47
合計ジャッジ時間 2,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   scanf("%llu%llu",&N,&M);
      |   ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define ll long long
#define ull unsigned ll

template<class T> T GCD(T a,T b){T r; while(a){r=b; b=a; a=r%a;} return b;}

int main(){
  int i, j, k;
  int p2 = 0, p5 = 0;
  ull N, M, g;

  scanf("%llu%llu",&N,&M);
  g = GCD(N,M);
  N /= g; M /= g;

  while(M%2==0) M/=2, p2++;
  while(M%5==0) M/=5, p5++;
  if(M>1){ puts("-1"); return 0; }

  while(N%10==0) N /= 10;
  N %= 10;
  while(p2>p5) p5++, N=(N*5)%10;
  while(p2<p5) p2++, N=(N*2)%10;

  printf("%d\n",(int)N);

  return 0;
}
0