結果
問題 | No.747 循環小数N桁目 Hard |
ユーザー |
![]() |
提出日時 | 2019-06-25 00:36:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,700 bytes |
コンパイル時間 | 1,715 ms |
コンパイル使用メモリ | 169,684 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 18:31:30 |
合計ジャッジ時間 | 5,309 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 120 |
コンパイルメッセージ
main.cpp: In function 'll mod6(ll, ll)': main.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type] 53 | } | ^
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<<endl #define p2(s, t) cout << (s) << " " << (t) << endl #define br() p("") #define pn(s) cout << (#s) << " " << (s) << endl #define p_yes() p("Yes") #define p_no() p("No") const ll mod = 1e9 + 7; const ll inf = 1e18; ll ll_pow(ll a, ll n){ ll ans = 1; FOR(i, 0, n){ ans *= a; } return ans; } ll ctoi(char c ){ ll v = c - '0'; return v; } ll string_sum(string s){ ll sum = 0; for(char c : s){ sum += ctoi(c); } return sum; } ll mod2(string s){ ll v = ctoi(s.back()); return v % 2; } ll mod6(ll mod2, ll mod3){ if(mod2==0 && mod3==0) return 0; if(mod2==1 && mod3==1) return 1; if(mod2==0 && mod3==2) return 2; if(mod2==1 && mod3==0) return 3; if(mod2==0 && mod3==1) return 4; if(mod2==1 && mod3==2) return 5; } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input string N, K; cin >> N >> K; // N mod 6 ll N_mod_3 = string_sum(N) % 3; // pn(N_mod_3); ll N_mod_2 = mod2(N); // pn(N_mod_2); ll N_mod_6 = mod6(N_mod_2, N_mod_3); // K mod 2 ll K_mod_2 = mod2(K); if(K_mod_2==0) K_mod_2+=2; // pn(N_mod_6); // pn(K_mod_2); ll keta = ll_pow(N_mod_6, K_mod_2); // pn(keta); keta %= 6; if(keta==0) keta+=6; string s = "285714"; p(s[keta-1]); return 0; }