結果
問題 | No.2902 ZERO!! |
ユーザー | shiba |
提出日時 | 2024-09-27 20:49:54 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 5,867 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 159,864 KB |
実行使用メモリ | 7,616 KB |
最終ジャッジ日時 | 2024-09-27 20:49:58 |
合計ジャッジ時間 | 3,823 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
6,812 KB |
testcase_01 | AC | 6 ms
6,944 KB |
testcase_02 | AC | 81 ms
7,616 KB |
testcase_03 | AC | 7 ms
6,940 KB |
testcase_04 | AC | 21 ms
6,940 KB |
testcase_05 | AC | 44 ms
6,944 KB |
testcase_06 | AC | 74 ms
7,448 KB |
testcase_07 | AC | 25 ms
6,940 KB |
testcase_08 | AC | 71 ms
7,296 KB |
testcase_09 | AC | 72 ms
7,168 KB |
testcase_10 | AC | 53 ms
6,940 KB |
testcase_11 | AC | 47 ms
6,940 KB |
testcase_12 | AC | 11 ms
6,940 KB |
testcase_13 | AC | 72 ms
7,160 KB |
testcase_14 | AC | 59 ms
6,940 KB |
testcase_15 | AC | 63 ms
6,940 KB |
testcase_16 | AC | 38 ms
6,944 KB |
testcase_17 | AC | 71 ms
7,040 KB |
testcase_18 | AC | 70 ms
6,944 KB |
testcase_19 | AC | 59 ms
6,940 KB |
testcase_20 | AC | 49 ms
6,940 KB |
testcase_21 | AC | 55 ms
6,940 KB |
testcase_22 | AC | 28 ms
6,940 KB |
testcase_23 | AC | 42 ms
6,944 KB |
testcase_24 | AC | 6 ms
6,940 KB |
testcase_25 | AC | 6 ms
6,940 KB |
testcase_26 | AC | 6 ms
6,944 KB |
testcase_27 | AC | 6 ms
6,944 KB |
testcase_28 | AC | 6 ms
6,944 KB |
testcase_29 | AC | 6 ms
6,944 KB |
testcase_30 | AC | 6 ms
6,940 KB |
testcase_31 | AC | 7 ms
6,944 KB |
testcase_32 | AC | 6 ms
6,944 KB |
testcase_33 | AC | 6 ms
6,940 KB |
testcase_34 | AC | 6 ms
6,940 KB |
testcase_35 | AC | 6 ms
6,940 KB |
testcase_36 | AC | 6 ms
6,944 KB |
testcase_37 | AC | 6 ms
6,940 KB |
testcase_38 | AC | 6 ms
6,944 KB |
testcase_39 | AC | 6 ms
6,944 KB |
testcase_40 | AC | 6 ms
6,940 KB |
testcase_41 | AC | 6 ms
6,944 KB |
testcase_42 | AC | 6 ms
6,944 KB |
testcase_43 | AC | 6 ms
6,944 KB |
ソースコード
#include <iostream> // cout, endl, cin #include <iterator> #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> #include <climits> #include <cmath> #include <functional> #include <numeric> #include <regex> #include <array> #include <fstream> #include <sstream> // #include <atcoder/dsu> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define repl(i,l,r) for (int i = l; i < (int)(r); i++) #define all(a) a.begin(),a.end() #define Pii pair<int,int> #define Pll pair<long,long> #define INFi 1000000001 #define INFl 1000000000000000001 using namespace std; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> void printArray(vector<T>&A){ for(T&a:A){ cout<<a<<" "; } cout<<endl; } template<class T> void printArrayln(vector<T>&A){ for(T&a:A){ cout<<a<<endl; } } template<class T1,class T2> std::ostream &operator<<(std::ostream &out, const pair<T1,T2> &A){ cout<<"{"<<A.first<<","<<A.second<<"}"; return out; } template<class T1,class T2> std::ostream &operator<<(std::ostream &out, const map<T1,T2> &M){ for(const auto&A:M){ cout<<"{"<<A.first<<","<<A.second<<"}"; } return out; } template<class T1> std::ostream &operator<<(std::ostream &out, const set<T1> &M){ cout<<"{"; for(const auto&A:M){ cout<<A<<", "; } cout<<"}"<<endl; return out; } template<class T1> std::ostream &operator<<(std::ostream &out, const multiset<T1> &M){ cout<<"{"; for(const auto&A:M){ cout<<A<<", "; } cout<<"}"<<endl; return out; } template<class T> std::ostream &operator<<(std::ostream &out, const vector<T> &A){ for(const T &a:A){ cout<<a<<" "; } return out; } void print() { cout << endl; } template <typename Head, typename... Tail> void print(Head H, Tail... T) { cout << H << " "; print(T...); } template<class T> std::istream &operator>>(std::istream &in,vector<T>&A){ for(T&a:A){ std::cin>>a; } return in; } // modint: mod 計算を int を扱うように扱える構造体 template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<998244353>; int main(void){ std::cin.tie(0)->sync_with_stdio(0); int N;cin>>N; // Nの階乗に、それぞれの素因数がいくつ含まれているか vector<int> cnt; vector<int> numbers(N+1); rep1(i,N)numbers[i]=i; for(int i=2;i<=N;i++){ if(numbers[i]==1)continue; cnt.push_back(0); for(int j=i;j<=N;j+=i){ while(numbers[j]%i==0){ numbers[j]/=i; cnt.back()++; } } } int prev = -1; vector<int> cnt2; vector<int> num; for(auto&c:cnt){ if(c==prev){ cnt2.back()++; }else{ prev = c; cnt2.push_back(1); num.push_back(c); } } mint sum = 1; mint ans = 0; for(int i=1000000;i>=1;i--){ mint tmp = 1; rep(j, cnt2.size()){ if(num[j]/i==0)break; tmp *= modpow(mint(num[j]/i+1), cnt2[j]); } tmp -= sum; sum += tmp; ans += tmp * mint(i); } cout<<ans<<endl; }