結果
問題 | No.2891 Mint |
ユーザー |
![]() |
提出日時 | 2024-09-14 07:34:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 3,867 bytes |
コンパイル時間 | 1,852 ms |
コンパイル使用メモリ | 195,904 KB |
最終ジャッジ日時 | 2025-02-24 08:25:47 |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
#include<bits/stdc++.h>// #include<atcoder/all>// #include<boost/multiprecision/cpp_int.hpp>using namespace std;// using namespace atcoder;// using bint = boost::multiprecision::cpp_int;using ll = long long;using ull = unsigned long long;using ld = long double;using P = pair<ll,ll>;using vi = vector<ll>;using vvi = vector<vi>;using vvvi = vector<vvi>;using ve = vector<vector<int>>;using vb = vector<bool>;using vvb = vector<vb>;#define rep(i,n) for(ll i = 0;i < (ll)n;i++)#define ALL(x) (x).begin(),(x).end()#define sz(c) ((ll)(c).size())#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())// #define MOD 1000000007#define MOD 998244353template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}template< int mod >struct ModInt {int x;ModInt() : x(0) {}ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}ModInt operator-() const { return ModInt(-x); }ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }bool operator==(const ModInt &p) const { return x == p.x; }bool operator!=(const ModInt &p) const { return x != p.x; }ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;while(b > 0) {t = a / b;swap(a -= t * b, b);swap(u -= t * v, v);}return ModInt(u);}ModInt pow(int64_t n) const {ModInt ret(1), mul(x);while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}friend ostream &operator<<(ostream &os, const ModInt &p) {return os << p.x;}friend istream &operator>>(istream &is, ModInt &a) {int64_t t;is >> t;a = ModInt< mod >(t);return (is);}static int get_mod() { return mod; }};using modint = ModInt< MOD >;using mvi = vector<modint>;using mvvi = vector<mvi>;int main(){ios_base::sync_with_stdio(0), cin.tie(0);ll n,m;cin >> n >> m;ll sq = sqrt(m);modint res = 0;for(ll k = 1;k <= 10*sq;k++){if(m/k <= sq || k > n)break;res += (m%k);}modint inv = ((modint)2).inverse();for(ll l = 1;l <= sq;l++){ll a = m/l,b = m/(l+1)+1;if(b > n || b > a)continue;chmin(a,n);// cout << a << " " << b << " a\n";res += (m%MOD)*((a-b+1)%MOD)%MOD;modint k = l*((a-b+1)%MOD)%MOD;k = k*((a+b)%MOD);k *= inv;res -= k;}if(n > m)res += (m%MOD)*((n-m)%MOD)%MOD;cout << res << "\n";return 0;}