题意

题目链接

求满足\(i^2 + j^2 \% M = 0\)的数对\((i, j)\)的个数,\(1 \leqslant i, j \leqslant 10^9, M \leqslant 1000\)

Sol

发这篇博客的目的就是为了证明一下我到底有多菜。

mdzz小学组水题我想了40min都没想出来。这要是出在NOIP 2019的话估计我又要做不出Day1T1了。。

\(i^2 + j^2 \% M = i \% M * i \% M + j \% M * j \% M\)

枚举剩余系即可

此题完结

  1. /*
  2. */
  3. #include<bits/stdc++.h>
  4. #define Pair pair<int, int>
  5. #define MP(x, y) make_pair(x, y)
  6. #define fi first
  7. #define se second
  8. #define int long long
  9. #define LL long long
  10. #define rg register
  11. #define pt(x) printf("%d ", x);
  12. #define Fin(x) {freopen(#x".in","r",stdin);}
  13. #define Fout(x) {freopen(#x".out","w",stdout);}
  14. using namespace std;
  15. const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
  16. const double eps = 1e-9;
  17. inline int read() {
  18. char c = getchar(); int x = 0, f = 1;
  19. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  20. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  21. return x * f;
  22. }
  23. int N, M, vis[3001][3001];
  24. int get(int l, int r) {
  25. return (r - l) / M + (l > 0);
  26. }
  27. main() {
  28. N = read(); M = read();
  29. int ans = 0;
  30. for(int i = 1; i <= M; i++) {
  31. for(int j = 1; j <= M; j++) {
  32. if((i * i + j * j) % M == 0) {
  33. vis[i % M][j % M] = 1;
  34. }
  35. }
  36. }
  37. for(int i = 0; i <= min(N, M); i++)
  38. for(int j = 0; j <= min(N, M); j++)
  39. if(vis[i][j] && ((i * i + j * j) % M == 0))
  40. (ans += get(i, N) * get(j, N));
  41. cout << ans;
  42. return 0;
  43. }
  44. /*
  45. */

cf1056B. Divide Candies(数论 剩余系)的更多相关文章

  1. Divide Candies CodeForces - 1056B (数学)

    Arkady and his friends love playing checkers on an n×nn×n field. The rows and the columns of the fie ...

  2. Mail.Ru Cup 2018 Round 3 B. Divide Candies

    题目链接 分析一下题意可以得到题目要求的是满足下面这个 公式的不同的i,ji,ji,j的方案数; 即(i2+j2)mod&ThinSpace;&ThinSpace; m=0 (n ≤  ...

  3. [codeforces Mail.Ru Cup 2018 Round 3][B Divide Candies ][思维+数学]

    https://codeforces.com/contest/1056/problem/B 题意:输入n,m    求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<= ...

  4. 数论剩余系——cf1089F

    关于模和互质,很好的题目 /* n两个质因子 x,y有 ax+by=n-1 ax+by=n-1 ax+1+by=n y|ax+1 gcd(x,y)=1 ax%y,a取[1,y-1],就会有[1,y-1 ...

  5. Mail.Ru Cup 2018 Round 3 Solution

    A. Determine Line Water. #include <bits/stdc++.h> using namespace std; ]; int main() { while ( ...

  6. 【CSP-J 2021】总结

    前言:程不在长,能过则行.码不在多,无虫则灵.斯是信竞,惟吾爆零.线段维护快,树状跳的勤.数论剩余系,图论前向星.无数竞之推理,无物竞之劳形.大佬楼教主,超奆姚期智,神犇云:您太强了. 早上5:00就 ...

  7. poj---(2886)Who Gets the Most Candies?(线段树+数论)

    Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10373   Acc ...

  8. 数论算法 剩余系相关 学习笔记 (基础回顾,(ex)CRT,(ex)lucas,(ex)BSGS,原根与指标入门,高次剩余,Miller_Rabin+Pollard_Rho)

    注:转载本文须标明出处. 原文链接https://www.cnblogs.com/zhouzhendong/p/Number-theory.html 数论算法 剩余系相关 学习笔记 (基础回顾,(ex ...

  9. ACM学习历程—HDU5407 CRB and Candies(数论)

    Problem Description CRB has N different candies. He is going to eat K candies.He wonders how many co ...

随机推荐

  1. 线性表中顺序表的的理解和实现(java)

    线性表的顺序表示指的是用一组地址连续的存储单元以此存储线性表的数据元素,这种表示也称作线性表的顺序存储结构或顺序映像.通常,称这种存储结构的线性表为顺序表.特点是:逻辑上相邻的数据元素,其物理次序上也 ...

  2. Java NIO学习与记录(五): 操作系统的I/O模型

    操作系统的I/O模型 在开始介绍NIO Reactor模式之前,先来介绍下操作系统的五种I/O模型,了解了这些模型,对理解java nio会有不小的帮助. 先来看下一个服务端处理一次网络请求的流程图: ...

  3. Dijkstra+优先队列 堆优化

    关于堆优化 传统\(Dijkstra\),在选取中转站时,是遍历取当前最小距离节点,但是我们其实可以利用小根堆(STL的priority_queue)优化这个过程,从而大大降低复杂(\(O(V2+E) ...

  4. 如何给oneindex网盘增加评论、密码查看、read me,头提示功能。

    来自我的博客:www.resource143.com 微信公众号:资源库resource 视频教程地址 点击查看 评论功能 特性 使用 GitHub 登录 支持多语言 [en, zh-CN, zh-T ...

  5. 2019.04.11 第四次训练 【 2017 United Kingdom and Ireland Programming Contest】

    题目链接:  https://codeforces.com/gym/101606 A: ✅ B: C: ✅ D: ✅ https://blog.csdn.net/Cassie_zkq/article/ ...

  6. (转)DB2性能优化 – 如何通过调整锁参数优化锁升级

    原文:http://blog.51cto.com/5063935/2074306 1.概念描述 所谓的锁升级(lock escalation),是数据库的一种作用机制,为了节约内存的开销, 其会将为数 ...

  7. (转)MySQL出现同步延迟有哪些原因?如何解决?

    http://oldboy.blog.51cto.com/2561410/1682147----MySQL出现同步延迟有哪些原因?如何解决? 原文:http://www.zjian.me/mysql/ ...

  8. Python离线安装依赖包

    1.制作requirement.txt pip freeze > requirement.txt 2.下载离线Pytho安装包 pip download -r requirement.txt - ...

  9. Freemarker不显示对象的属性

    Freemarker不显示对象的属性 今天使用Freemarker在springboot项目中通过模板生成一些html文件.但是发现没有显示对象的属性. 找了很长时间,终于发现不显示对象的属性可能是两 ...

  10. PHP之mb_stripos使用

    mb_stripos (PHP 5 >= 5.2.0, PHP 7) mb_stripos - Finds position of first occurrence of a string wi ...