码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-09-03 22:27:27      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:org   its   isp   https   数论   row   amp   end   line   

题目

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;
}

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

标签:org   its   isp   https   数论   row   amp   end   line   

原文地址:https://www.cnblogs.com/y2823774827y/p/11455829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!