QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820796#3161. Another Coin Weighing Puzzleumd-red#AC ✓71ms11772kbC++203.2kb2024-12-19 02:25:232024-12-19 02:25:24

Judging History

你现在查看的是最新测评结果

  • [2024-12-19 02:25:24]
  • 评测
  • 测评结果:AC
  • 用时:71ms
  • 内存:11772kb
  • [2024-12-19 02:25:23]
  • 提交

answer

//Remember: (a mod m)/b IS NOT (a/b) mod m
//Checklist: multitest (!!), maxn, mod, constraints, NEGATIVE ANSWER
#include <iostream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<random>
#include<stack>
#include<chrono>
using namespace std;

//#define labeltc
#define endl "\n"
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
//#define MOD 1000000007
#define MOD 998244353
#define INFLL 2000000000001000000LL
#define INFI 1001000000
#define PI ((ld)(M_PI))
#define pii pair<int,int>
#define piii tuple<int,int,int>
#define pll pair<ll,ll>
#define plll tuple<ll,ll,ll>
#define fi first
#define sc second
#define m_p make_pair
#define p_b emplace_back
#define l_b lower_bound
#define u_b upper_bound
#define vi vector<int>
#define vl vector<ll>
#define rand_num(x,y) uniform_int_distribution<ll>((ll)x,(ll)y)(rng)
#define lsb(x) (x&(-x))
#define dgt(x) (x-'0')
#define all(x) x.begin(),x.end()
#define pans(x) ((x)? "YES " : "NO ")
template<typename T> bool ckmin(T& a, const T& b) {return (a>b)? a = b, 1 : 0;}
template<typename T> bool ckmax(T& a, const T& b) {return (a<b)? a = b, 1 : 0;}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll power(ll x, ll e, ll m = MOD){
    ll r = 1;
    while(e>0){
        if(e%2) r = (r*x)%m;
        x = (x*x)%m;
        e >>= 1;
    }
    return r;
}

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T,U>& v){
    os << v.fi << " " << v.sc;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
    for (int i = 0; i < v.size(); ++i) {os << v[i] << " ";}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
    for (auto it : v) {os << it << " ";}
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T,U>& v){
    for (auto it : v) {os << it << "\n";}
    return os;
}
template <typename T, typename U, typename W>
ostream& operator<<(ostream& os, const tuple<T,U,W>& v){
    os << sp(get<0>(v)) << sp(get<1>(v)) << sp(get<2>(v));
    return os;
}

void setIO(string s) {
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}

const int M = 1E6+10;

int mob[M];
vi lp(M),pr;

int n,k;


void precomp(){
    mob[1] = 1;
    for (int i=2; i<M; i++){
        if(lp[i] == 0){
            lp[i] = i;
            mob[i] = -1;
            pr.p_b(i);
        }
        for (int j=0; j < pr.size() && pr[j] <= lp[i] && 1ll*i*pr[j] < 1ll*M; j++){
            lp[i*pr[j]] = pr[j];
            if(i%pr[j] == 0) mob[i*pr[j]] = 0;
            else mob[i*pr[j]] = mob[i]*mob[pr[j]];
        }
    }
}

void solve(){
    cin >> n >> k;
    ll ans = 0;
    for (int i=1; i<=k; i++) {
        ans += power(2 * (k/i) + 1, n)*mob[i];
        ans %= MOD;
        ans = (ans+MOD)%MOD;
    }
    for (int i=1; i<M; i++) mob[i] += mob[i-1];
    ans -= mob[k];
    ans += 1;
    cout << (ans+MOD)%MOD << endl;
    ll ans2 = 0;
}

signed main(){
    //setIO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    precomp();
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 11636kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 4ms
memory: 11688kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 4ms
memory: 11628kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 6ms
memory: 11736kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 8ms
memory: 11732kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 6ms
memory: 11728kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 18ms
memory: 11632kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 3ms
memory: 11696kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 19ms
memory: 11532kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 6ms
memory: 11496kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 16ms
memory: 11636kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 15ms
memory: 11488kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

score: 0
Accepted
time: 10ms
memory: 11532kb

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 71ms
memory: 11732kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 43ms
memory: 11512kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 4ms
memory: 11772kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'