tjut 4896

#include <cstdio>  
#include <cstring>  
#include <algorithm>  
#include <cmath>   
#include <string>  
#include <map>  
#define eps 1e-9  
#define LL long long  
#define mod 2333333  
using namespace std;  
map <int , int> ma;  
int pos[100];  
int clo,p,ed;  
struct node  
{  
    int x,y,w;  
}a[250000];  
int f[500];  
LL te[200];  
int cmp(node a,node b)  
{  
    return (a.w<b.w);  
}  
int getf(int x)  
{  
    if (x==f[x]) return x;  
    else return (f[x]=getf(f[x]));  
}  
int unite(int x,int y)  
{  
    // printf("%d %d\n",x,y);  
    if (getf(x)!=getf(y)) f[getf(x)]=getf(y);  
}  
LL kru()  
{  
    LL ans=0;  
    for (int i=1;i<=ed;i++)  
        if (getf(a[i].x)!=getf(a[i].y)) {  
            ans+=a[i].w;  
            unite(a[i].x,a[i].y);  
        }  
    return ans;  
}  
int main()  
{  
    LL n,seed;  
    while (~scanf("%I64d%I64d",&n,&seed))  
    {  
        ma.clear();  
        int cur=seed;  
        int t=0;  
        while (ma[cur]==0)  
        {  
            t++;  
            pos[t]=cur;  
            pos[0]=cur;  
            ma[cur]=1;  
            cur=cur*907%mod;  
        }  
        for (int k=1;k<=108;k++)  
        {  
  
            for (int i=1;i<=k;i++)  
                f[i]=i;  
            clo=ed=0;  
            for (int i=1;i<=k;i++)  
            {  
                clo++;  
                clo%=54;  
                p=pos[clo];  
                for (int j=max(1,i-5);j<i;j++)  
                {  
                    clo++;  
                    clo%=54;  
                    ed++;  
                    a[ed].x=i;  
                    a[ed].y=j;  
                    a[ed].w=pos[clo]^p;  
                }  
            }  
        sort(a+1,a+1+ed,cmp);  
        te[k]=kru();//暴力前108个结果  
        }  
        // for (int i=1;i<=100;i++)  
        //  printf("%I64d ",te[i]);  
        if (n<=108) printf("%I64d\n",te[n]);  
        else printf("%I64d\n",te[54+n%54]+(n/54-1)*(te[108]-te[54]));  
    }  
    return 0;  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值