牛客挑战赛37

牛客挑战赛37

写在前面

随机模数(香)
__lg==log2 __lg返回整形下对2的对数,想当快。log2就会超时(真香)

A牛牛与序列计数
在这里插入图片描述
数学题==找规律(for me)

#pragma GCC optimize(3,"Ofast","inline")    //G++
#include<bits/stdc++.h>
#define TEST freopen("C:\\Users\\hp\\Desktop\\ACM\\in.txt","r",stdin);
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<<setprecision(4)<<fixed
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
 
 
const int inf=0x3f3f3f3f;
const ll INF=0x7fffffffffffffff;
const int mod=1e9+7;
const int maxn = 1e6+5;
const double eps=1e-8;
 
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}
int sgn(double a){
    return a<-eps?-1:a<eps?0:1;
}
 
ll fast_pow(ll a,ll b,ll p=mod)
{
    a%=mod;
    if(a==0) return 0;
    ll ret=1;
    for(; b; b>>=1,a=a*a%p)
        if(b&1) ret=ret*a%p;
    return ret%p;
}
void solve(){
    ll n;
    read(n);
    if(n&1) cout<<"0\n";
    else
    {
        n/=2;
        ll ans=fast_pow(2,4*n-3);
        cout<<ans<<"\n";
    }
}
int main()
{
     solve();
}

B 牛牛与组合数学
在这里插入图片描述
这种题做三次了,随机模数。。。下次要思考这个方向
卢卡斯+随机模数

#include<bits/stdc++.h>
#define ll long long
//#define mod (ll)(1e9+7)
using namespace std;
ll mod;
ll a[100005];
const ll MOD[] = {2, 3, 5, 7, 11, 31, 71, 97, 233, 397, 433, 449, 607, 857, 10007, 21179, 36251, 44579, 62003, 72883, 97843, 139991, 232013, 369353, 681521, 692711, 777241, 822821, 1956761, 2145137, 2915837, 6229117, 7788787, 13743493, 17331841, 19260817, 19269293, 19959809, 21006959, 23937083, 24410849, 28452757, 28478603, 29229359, 35570827, 35604011, 35875487, 37370863, 38303347, 38475517, 38819149, 40455791, 44021539, 45641993, 46531301, 48866749, 50529641, 52634191, 52790587, 55180799, 56971613, 58259351, 60954737, 62207269, 63367453, 65072599, 66017821, 67952779, 69475349, 74689217, 77059907, 77907121, 79391659, 84768797, 85584601, 85724879, 85756609, 86850899, 91783511, 92331541, 94519499, 96375241, 99033413, 99486311, 100569829, 106873549, 109329881, 109913681, 111186487, 111894067, 112136617, 112417363, 114011921, 119143363, 122994493, 123747781, 124001021, 126515639, 128191039, 128767909, 132222763, 133587661, 139644719, 145641527, 153388423, 155187077, 156883333, 157989581, 159538063, 161488643, 164039129, 166070447, 169181543, 169554227, 173564801, 175742867, 185469637, 187203899, 191263223, 198691817, 204144887, 211631201, 217903877, 218028203, 220073423, 228143453, 228667423, 232064653, 240519263, 245647159, 247586411, 247936121, 250949197, 253413211, 253464329, 260572729, 260590409, 262887773, 265711423, 266763641, 273585149, 276472817, 276500531, 280543667, 280649591, 281385491, 291366337, 293273159, 296973107, 302890501, 306568693, 315614297, 316729409, 317617121, 320337781, 320613497, 321322823, 324691051, 325963067, 327184157, 329900633, 330670159, 332058781, 332213669, 332300869, 334382221, 341895677, 347938237, 349011827, 349347503, 349906439, 353796941, 364557253, 364755931, 367946441, 372413831, 374358983, 379589897, 381149689, 389431873, 404683493, 405216109, 405495029, 408142403, 408989747, 410841979, 410935093, 412405351, 412592459, 412722139, 412990573, 418171483, 421270357, 424233613, 427938449, 428492083, 429962881, 430883569, 434988383, 435941201, 438816151, 440052953, 440143589, 444693631, 453646433, 455847109, 456640189, 457911511, 458185237, 463116761, 463861417, 469275953, 471298573, 471712513, 478267417, 483824813, 494828483, 497397293, 499657393, 507957479, 512906621, 519346459, 519879973, 520094713, 523213693, 525673273, 529575763, 529883803, 533887031, 534260809, 535328309, 541992667, 542253071, 544780177, 545567609, 552922529, 555129893, 555820037, 558473471, 563484017, 571310471, 578121241, 582251063, 583825639, 584121323, 592038487, 599098811, 601467677, 610073969, 615059213, 619220713, 622457177, 627412609, 630547919, 632342989, 637357363, 638865419, 648268013, 650007487, 651564761, 654115433, 661281713, 662664461, 667914281, 682988213, 691099121, 691445809, 692038043, 692411953, 698620943, 699007259, 701164631, 706806461, 707096251, 707697451, 709566589, 719095829, 725756807, 736880491, 739603867, 743026709, 744236861, 744396049, 747393791, 749395103, 760341121, 762934307, 773124059, 773195911, 776162609, 781629113, 781884613, 786120631, 788314343, 788898377, 788939293, 790209983, 791933183, 796328783, 798643889, 802280047, 803293991, 803847559, 809752739, 818520473, 820434047, 826810489, 829359959, 829707427, 836587463, 841011167, 843763253, 849410557, 851226437, 853058471, 853168793, 853778327, 859086391, 860720017, 863193077, 873061181, 888803059, 893035529, 900902953, 904636883, 917949577, 921817139, 922328707, 931449133, 933074827, 933156233, 935241721, 935632799, 939948881, 957119773, 961329913, 965269573, 965337949, 967551691, 971080093, 973578143, 976825877, 985100197, 985413691, 986124823, 990650057, 998244353, 999058883, 1000000007,0};
ll Pow(ll a,ll b)
{
    a%=mod;
    ll ans = 1;
    while(b)
    {
        if(b&1)
            ans = (ans*a)%mod;
        a = (a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
ll Quk(ll a,ll b)
{
    a%=mod;
    ll ans = 0;
    while(b)
    {
        if(b&1)
            ans = (ans+a)%mod;
        a = (a+a)%mod;
        b/=2;
    }
    return ans%mod;
}
ll C(ll n,ll m)
{
    if(m>n) return 0;
    return Quk(Quk(a[n],Pow(a[n-m],mod-2)),Pow(a[m],mod-2))%mod;
}
ll A(ll n,ll m)
{
    return Quk(a[n],Pow(a[n-m],mod-2))%mod;
}
ll Lucas(ll n,ll m)
{
    if(!m)return 1;
    return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
ll get_mod(string a,ll b)//高精度a除以单精度b--算法复杂度O(n)
{
    ll d=0;
    for(ll i=0; i<(int)a.size(); i++) d=(d*10+(a[i]-'0'))%b; //求出余数
    return d;
}
main()
{
    ll n, m;
    string p;
    cin >> n >> m>>p;
    for (ll j= 0;MOD[j];j++)
    {
        mod = MOD[j];
        if(mod>1e5)
            break;
        a[0] = a[1] = 1;
        for (ll i = 2;i<=mod;i++){
            a[i] = Quk(a[i - 1], i);
        }
        if(Lucas(n,m)!=get_mod(p,mod)){
            cout<<"No!\n";
            return 0;
        }
    }
    cout << "Yes!\n";
}

模数是之前遇到时,粘贴的别人的好像300多个吧,挺全的。
C 牛牛要女装
在这里插入图片描述
照着题目模拟就行,主要是学到了__lg(香)

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull n,m,f,t;
void build(ull n,ull base,ull l)
{
    ull q=((ull)1<<(int)(__lg(n)));
    if(l==m)
    {
        f=base+q;
        return ;
    }
    else if(l+q>m)
        build(q-1,base,l+1);
    else
        build(n-q,base+q,l+q);
}
int main()
{
    scanf("%llu",&t);
    while(t--)
    {
        f=0;
        scanf("%llu%llu",&n,&m);
        build(n,0ll,1ll);
        printf("%llu\n",f);
    }
    return 0;
}

D,E总共只有15个人过。。。。溜

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值