关于奇怪的WA90分
查看原帖
关于奇怪的WA90分
144044
XMK_萌新楼主2021/8/20 18:02

RT

#3 不知为何 WA 了,能不能帮忙看一下鸭 qaq

#include <iostream>
#define ll long long
using namespace std;
int n,m; ll ans,p[33];
void search(ll orz,int id,int total_chosen)
{
    if(orz>m) return;	//及时退出
    if(id==n+1)
    {
        if(!total_chosen) return;
        if(total_chosen%2) ans+=orz*(1+m/orz)*(m/orz)/2;	//容斥,奇+偶-
        else ans-=orz*(1+m/orz)*(m/orz)/2;
        if(ans>=376544743) ans%=376544743;
        return;
    }
    search(orz*p[id],id+1,total_chosen+1);	//选
    search(orz,id+1,total_chosen);	//不选
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>p[i];
    search(1LL,1,0);	//当前已选择质数乘积/考虑的质数编号/已选质数数目
    cout<<ans;
    return 0;
}
2021/8/20 18:02
加载中...