题意

题目链接

求满足\(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\)

枚举剩余系即可

此题完结

/*
*/
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define rg register
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, vis[3001][3001];
int get(int l, int r) {
return (r - l) / M + (l > 0);
}
main() {
N = read(); M = read();
int ans = 0;
for(int i = 1; i <= M; i++) {
for(int j = 1; j <= M; j++) {
if((i * i + j * j) % M == 0) {
vis[i % M][j % M] = 1;
}
}
}
for(int i = 0; i <= min(N, M); i++)
for(int j = 0; j <= min(N, M); j++)
if(vis[i][j] && ((i * i + j * j) % M == 0))
(ans += get(i, N) * get(j, N));
cout << ans;
return 0;
}
/* */

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. 总结day24 ---- socket ,struct 的学习

    前情提要 一:套接字  socket()  1:三次握手 1:客户端像服务端链接,   (第一次握手) 2:服务端收到请求,告诉客户端服务端收到了内容    (第二次握手1) 3:服务端像客户端连接, ...

  2. npm 常用配置

    npm config list/ls 显示配置信息npm config list/ls -l 更详细npm -h 显示帮助信息,建议多查看npm -l display full usage info ...

  3. 架构师养成记--33.Redis哨兵、redis简单事务

    Redis哨兵 有了主从复制,如果我想想对主从服务器进行监控,在redis2.6后提供了哨兵机制,2.6有哨兵1.0版本,并不稳定.2.8以后的哨兵功能才稳定起来. 顾名思义,哨兵就是监控Redis系 ...

  4. L04-VirtualBox中CentOS7网络配置(可连外网)

    本文所述的方法在RHEL6.5.RHEL7和CentOS6.5中同样适用. 1.工具:VirtualBox,虚拟机:CentOS7 2.VirtualBox工具中的网络配置 (1)VirtualBox ...

  5. OpenERP 干掉 产品计量单位中的 search more 和 create and edit

    实际操作中特别容易点错而新建了重复的单位,通过下边的方法可以将“search more”和 “create and edit”干掉 在新继承product.product的模块中,修改xml文件 这样 ...

  6. Sublime Text 3安装插件(Mac 10.12)

    1.先安装Package Control,默认这个是没有安装的. 使用[control + -]打开控制台,输入以下代码: import urllib.request,os; pf = 'Packag ...

  7. jQuery多库共存问题解决方法

    一.问题概述: 1.随着jQuery的流行,采用jQuery和$符为命名空间的js库越来越多,当然jQuery的$符也是参照的Prototype库的,所以当多个库同时以$符或者jQuery为命名空间时 ...

  8. solr7之solrJ的使用

    solr7的官网API介绍 网页翻译的不是很准确,只能了解个大概,基本能获取如下信息: 一.构建和运行SolrJ应用程序 对于用Maven构建的项目, pom.xml配置: <dependenc ...

  9. rspec中的let和let!区别

    文档 https://relishapp.com/rspec/rspec-core/v/2-5/docs/helper-methods/let-and-let 从上面文档中得出 let 1 只会在一个 ...

  10. Windows和Ubuntu双系统时间相差8个小时的问题

    由于要学编程,在windows 10上安装了Ubuntu16.04双系统.但是却造成windows时间老是比实际时间慢八个小时,Ubuntu会与网络同步时间,但是在程序中调用主板时间时仍然是UTC时间 ...