• Luogu4884 多少个1?(BSGS)


      11……1(n个)=99……9(n个)/9=(10n-1)/9。

      那么显然就是求离散对数了,BSGS即可。

    #include<iostream> 
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<map>
    using namespace std;
    #define ll long long
    ll read()
    {
        ll x=0,f=1;char c=getchar();
        while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
        while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        return x*f;
    }
    ll k,m,block,a[1000000];
    map<ll,ll> f;
    ll ksc(ll a,ll b)
    {
        ll t=a*b-(ll)((long double)a*b/m+0.5)*m;
        return t<0?t+m:t;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("a.in","r",stdin);
        freopen("a.out","w",stdout);
        const char LL[]="%I64d
    ";
    #else
        const char LL[]="%lld
    ";
    #endif
        k=read(),m=read();
        k=(k*9+1)%m;
        block=sqrt(m);f[a[0]=k]=1;ll s=1;
        for (int i=1;i<=block;i++) f[a[i]=a[i-1]*10%m]=i+1,s=s*10%m;
        ll t=s;
        for (ll i=block;i<=m+block;i+=block,s=ksc(s,t))
        if (f[s]) {cout<<i-f[s]+1;return 0;}
    }
  • 相关阅读:
    windows下pip安装python module失败
    设置jenkins的邮件通知功能
    jenkins 中 violation使用pylint
    pylint & jenkins
    dracut 基本介绍
    etcdctl 命令介绍
    python
    django --------------------- [必要操作]
    vim
    ssl选购
  • 原文地址:https://www.cnblogs.com/Gloid/p/9656632.html
Copyright © 2020-2023  润新知