欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #701 (Div. 2) C. Floor and Mod 数学分块

发布时间:2023/12/4 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Codeforces Round #701 (Div. 2) C. Floor and Mod 数学分块 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

传送门

题意: 给两个数x,yx,yx,y。现在你计算有多少对a(a<=x)a(a<=x)a(a<=x)b(b<=y)b(b<=y)b(b<=y)使得⌊ab⌋=amodb\left \lfloor \frac{a}{b} \right \rfloor=a\bmod bba=amodb

思路: 因为xxxyyy都是1e91e91e9的范围,可以想到n\sqrt{n}n求出答案。我们令⌊ab⌋=amodb=k\left \lfloor \frac{a}{b} \right \rfloor=a\bmod b=kba=amodb=k,那么aaa可以写成k∗b+kk*b+kkb+k,又因为k<bk<bk<b,那么k∗k<=k∗b+k=a<=xk*k<=k*b+k=a<=xkk<=kb+k=a<=x,可得k<=xk<=\sqrt{x}k<=x,现在考虑知道了kkk能否算出答案呢?考虑如下三个个不等式:{1<=b<=y1<=k∗b+k<=xk<b\begin{cases} 1<=b<=y\\ 1<=k*b+k<=x\\ k<b \end{cases}1<=b<=y1<=kb+k<=xk<b
解得:k<b<=min(y,x/k−1)k<b<=min(y,x/k-1)k<b<=min(y,x/k1)
我们枚举kkk就可以得到答案啦。

//#pragma GCC optimize(2) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<map> #include<cmath> #include<cctype> #include<vector> #include<set> #include<queue> #include<algorithm> #include<sstream> #include<ctime> #include<cstdlib> #define X first #define Y second #define L (u<<1) #define R (u<<1|1) #define pb push_back #define mk make_pair #define Mid (tr[u].l+tr[u].r>>1) #define Len(u) (tr[u].r-tr[u].l+1) #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define db puts("---") using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); } //void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); } //void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f; const double eps=1e-6;int x,y;int main() { // ios::sync_with_stdio(false); // cin.tie(0);int _; scanf("%d",&_);while(_--){LL ans=0;scanf("%d%d",&x,&y);for(LL k=1;k*k<x;k++) ans+=max(0ll,min(1ll*x/k-1,1ll*y)-k);printf("%lld\n",ans);}return 0; } /**/ 创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的Codeforces Round #701 (Div. 2) C. Floor and Mod 数学分块的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。