結果
問題 |
No.25 有限小数
|
ユーザー |
![]() |
提出日時 | 2015-06-08 22:06:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,263 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 86,756 KB |
実行使用メモリ | 250,368 KB |
最終ジャッジ日時 | 2024-07-06 14:53:20 |
合計ジャッジ時間 | 7,266 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 1 TLE * 1 -- * 13 |
ソースコード
#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; } map<ull,bool> memo; 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(memo.count(N)>0) break; memo[N] = true; if(N==0){ cout << ret << endl; return 0; } ret = N/M; while(ret>=10 && ret%10==0) ret = ret/10; N %= M; N *= 10LL; --keta; } cout << -1 << endl; return 0; }