牛客练习赛107(ABCD)

 A. 如见青山

当n! >= m时,(n!)!内存在因子m, 即答案为0

void solve()
{
    ll n;
    cin >>n;
    ll x = 1;
    fo(i,1,n)
    {
        x *= i;
        if(x >= mod)
        {
            cout << 0 << endl;
            return;
        }
    }
    cout << fac[x]%mod << endl;
}

B. 惊鹊

显然,次数只能为1或2,将p[1]置为1即可

void solve()
{
    int n;
    cin >> n;
    ve<int> a(n+1);
    fo(i,1,n) cin >> a[i];
    bool ok = 0;
    fo(i,1,n) if(a[i] != i) ok = 1;
    if(ok)
    {
        int id = 2;
        fo(i,1,n)
        {
            if(i == a[1]) cout << 1 << " ";
            else cout << id ++ << " ";
        }
    }
    else
    {
        fo(i,1,n) cout <<i << " ";
        err();
    }
}

C. 始见千秋

思路:暴力+分块

当 k<=\sqrt{n}时,暴力求解

k>\sqrt{n}时,k进制下只有两位,考虑数论分块

n%k在每一块内是递减的, 分块时二分n%k和n/k的分界处

ll n;
ll cn(ll x){
    ve<ll> g;
    ll y = n, res = 0;
    ll k = 0;
    while(y) 
    {
        k = max(y%x,k);
        g.pb(y%x), y/=x;
    }
    k ++;
    reverse(all(g));
    for(auto t : g) res = res * k + t;
    return res;
}
void solve()
{
    cin >> n;
    ll m = 2;
    ll ans = 0;
    while(m * m <= n) 
    {
        ll res = cn(m++);
        ans += res;
    }
    ll r, id,  w;
    for(; m <= n; m = r + 1)
    {
        r = n / (n / m), id = n / m;
        ans += (r-m+1)*n-id*(m+r)*(r-m+1)/2;
        ll l1 = m, r1 = r, now = m;
        while(l1 <= r1)
        {
            ll mid = l1 + r1 >> 1;
            if(id > n % mid) r1 = mid - 1,now=mid;
            else l1 = mid + 1;
        }
        now --;
        ans += id * ((now - m + 1) * n - id * (m + now) * (now - m + 1) / 2)+id * id * (r - now)+id * (r - m + 1);
    }
    cout << ans << endl;
}

 D. 补天裂

1的总个数是不变的,从an~a1依次赋值即可

void solve()
{
    int n;
    cin >> n;
    ve<int> a(n+1);
    fo(i,1,n) cin >> a[i];
    ve<int> cnt(70);
    fo(i,1,n) fo(j,0,32)
    if((a[i] >> j) & 1) cnt[j]++;
    ve<int> b(n+1);
    ro(i,n,1)
        fo(j,0,32)
            if(cnt[j] > 0) 
                b[i] |= (1 << j), cnt[j]--;
    fo(i,1,n) cout<< b[i]<<" ";
    err();
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值