跳到正文

题解

题解:P15790 「1&0OI R1」相思若循

_ZXY_约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年3月21日
更新
2026年3月21日
篇幅
约 2 分钟
题目
P15790

版本

  1. v2当前
  2. v1

推导

当然,我们从小部分来推导。 10pts∼20pts10\mathrm{pts}\sim20\mathrm{pts}:暴力找循环节。 50pts50\mathrm{pts}:暴力找循环节,打表。或你已经看出规律,用光速幂超时了。 100pts100\mathrm{pts}:你通过打表发现了规律:除了 11 以外,所有的解都是 2n−12^n-1!然后你写了光速幂,如果被卡到 50pts50\mathrm{pts},尝试减少取模次数。

AC Code
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p=998244353;
int T;
inline ll mul(ll x,ll y){
    ll res=0;
    while(y){
        if(y&1)res=(res+x);
        x=x+x;
        y>>=1;
    }
    return res;
}
inline ll qpow(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=mul(res,x)%p;
        x=mul(x,x)%p;
        y>>=1;
    }
    return res%p;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>T;
    while(T--){
        ll n;
        cin>>n;
        if(n==1)cout<<"NO\n";
        else{
            ll ans=(qpow(2,n)-1+p)%p;
            cout<<ans<<'\n';
        }
    }
    return 0;
}
原文