結果
問題 | No.2724 Coprime Game 1 |
ユーザー | 👑 Nachia |
提出日時 | 2024-04-12 21:30:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,695 bytes |
コンパイル時間 | 1,017 ms |
コンパイル使用メモリ | 97,472 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-02 23:01:22 |
合計ジャッジ時間 | 4,355 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
10,496 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
ソースコード
#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <queue> #include <array> #include <cmath> #include <atcoder/modint> namespace nachia{ long long CountingPrimes(long long maxval){ using i64 = long long; i64 n = maxval; if(n <= 1) return 0; i64 sqrtn = 0; while(sqrtn * sqrtn <= n) sqrtn++; sqrtn--; std::vector<i64> prefix_sum_fairy(sqrtn+1, 0); for(i64 i=1; i<=sqrtn; i++) prefix_sum_fairy[i] = i-1; std::vector<i64> prefix_sum_devil(sqrtn+1, 0); for(i64 i=1; i<=sqrtn; i++) prefix_sum_devil[i] = n/i-1; for(i64 p=2; p<=sqrtn; p++){ i64 prime_count_p = prefix_sum_fairy[p]; i64 prime_count_p_minus1 = prefix_sum_fairy[p-1]; if(prime_count_p == prime_count_p_minus1) continue; for(i64 devil_id = 1; devil_id <= sqrtn; devil_id++){ if(devil_id * p <= sqrtn){ prefix_sum_devil[devil_id] -= prefix_sum_devil[devil_id * p] - prime_count_p_minus1; } else{ i64 tg_fairy = n / (devil_id * p); if(tg_fairy < p) break; prefix_sum_devil[devil_id] -= prefix_sum_fairy[tg_fairy] - prime_count_p_minus1; } } for(i64 fairy_id = sqrtn/p; fairy_id >= p; fairy_id--){ i64 dc = prefix_sum_fairy[fairy_id] - prime_count_p_minus1; i64 max_tg = std::min(fairy_id * p + p - 1, sqrtn); for(i64 tg_fairy = fairy_id * p; tg_fairy <= max_tg; tg_fairy++) prefix_sum_fairy[tg_fairy] -= dc; } } return prefix_sum_devil[1]; } } // namespace nachia using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<int(n); i++) #define repr(i,n) for(int i=int(n)-1; i>=0; i--) const i64 INF = 1001001001001001001; const char* yn(bool x){ return x ? "Yes" : "No"; } template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; } template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; } template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>; using Modint = atcoder::static_modint<998244353>; //#include "nachia/vec.hpp" using namespace std; void unit(){ int N; cin >> N; int n = N/2+1; int c = N - 1 - nachia::CountingPrimes(N-1) + nachia::CountingPrimes(n-1); cout << (c%2 == 0 ? "K\n" : "P\n"); } void testcase(){ int T; cin >> T; rep(t,T) unit(); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef NACHIA int T; cin >> T; for(int t=0; t<T; T!=++t?(cout<<'\n'),0:0) #endif testcase(); return 0; }