CodeForces 1202F(数论,整除分块)

题目

CodeForces 1213G

做法

假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \frac{N}{K} \right \rfloor\)

假设循环快中有\(p_a,p_b\)\(A\)\(B\),则

  • \(p_a\cdot P\le a\Longrightarrow p_a\le \left \lfloor \frac{a}{P} \right \rfloor\)

  • \(p_a\cdot (P+1)\ge a\Longrightarrow p_a\ge \lceil \frac{a}{P+1} \rceil\)


\[\begin{aligned}\\ \lceil \frac{a}{P+1} \rceil \le p_a \le \left \lfloor \frac{a}{P} \right \rfloor\\ \lceil \frac{b}{P+1} \rceil \le p_b \le \left \lfloor \frac{b}{P} \right \rfloor\\ \end{aligned}\]

\(P\)可能的值可以整除分块算出来,\(O(\sqrt n)\)

Code

#include<bits/stdc++.h>
typedef int LL;
LL a,b,ans;
int main(){
    scanf("%d%d",&a,&b);
    LL len(a+b);
    for(LL i=1,r;i<=len;i=r+1){
        LL P(len/i);
        r=len/P;
        if(P>a || P>b) continue;
        LL an((a+P)/(P+1)),ax(a/P),bn((b+P)/(P+1)),bx(b/P);
        if(an<=ax && bn<=bx) ans+=std::min((ax+bx),r)-std::max((an+bn),i)+1;
    }
    printf("%d ",ans);
    return 0;
}

转载于:https://www.cnblogs.com/y2823774827y/p/11455829.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值