結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-01-15 21:44:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 619 bytes |
| コンパイル時間 | 2,096 ms |
| コンパイル使用メモリ | 198,840 KB |
| 最終ジャッジ日時 | 2025-01-17 18:55:27 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 WA * 24 |
コンパイルメッセージ
main.cpp: In function ‘ULL loop()’:
main.cpp:8:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | int N; scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:23:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | int T; scanf("%d",&T);
| ~~~~~^~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
ULL loop(){
int N; scanf("%d",&N);
while(N%2==0) N/=2;
while(N%5==0) N/=5;
if(N==1) return 1;
unordered_map<ULL,ULL> X(30000);
ULL p=1;
rep(i,30000){ X[p]=i; p=p*10%N; if(p==1) return i+1; }
p=1;
ULL inv=0; rep(i,10) if((N/10*i+1)*10%N==1) inv=N/10*i+1;
ULL q=1; rep(i,30000) q=q*inv%N;
rep(i,40000){ p=p*q%N; if(X.count(p)) return (i+1)*30000+X[p]; }
return ~0ull;
}
int main(){
int T; scanf("%d",&T);
while(T--) printf("%llu\n",loop());
return 0;
}
Nachia