cf1056B. Divide Candies(数论 剩余系)
题意
求满足\(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(数论 剩余系)的更多相关文章
- 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 ...
- Mail.Ru Cup 2018 Round 3 B. Divide Candies
题目链接 分析一下题意可以得到题目要求的是满足下面这个 公式的不同的i,ji,ji,j的方案数; 即(i2+j2)mod   m=0 (n ≤ ...
- [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<= ...
- 数论剩余系——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 ...
- Mail.Ru Cup 2018 Round 3 Solution
A. Determine Line Water. #include <bits/stdc++.h> using namespace std; ]; int main() { while ( ...
- 【CSP-J 2021】总结
前言:程不在长,能过则行.码不在多,无虫则灵.斯是信竞,惟吾爆零.线段维护快,树状跳的勤.数论剩余系,图论前向星.无数竞之推理,无物竞之劳形.大佬楼教主,超奆姚期智,神犇云:您太强了. 早上5:00就 ...
- poj---(2886)Who Gets the Most Candies?(线段树+数论)
Who Gets the Most Candies? Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 10373 Acc ...
- 数论算法 剩余系相关 学习笔记 (基础回顾,(ex)CRT,(ex)lucas,(ex)BSGS,原根与指标入门,高次剩余,Miller_Rabin+Pollard_Rho)
注:转载本文须标明出处. 原文链接https://www.cnblogs.com/zhouzhendong/p/Number-theory.html 数论算法 剩余系相关 学习笔记 (基础回顾,(ex ...
- ACM学习历程—HDU5407 CRB and Candies(数论)
Problem Description CRB has N different candies. He is going to eat K candies.He wonders how many co ...
随机推荐
- 如何使用Node爬虫利器Puppteer进行自动化测试
文:华为云DevCloud 乐少 1.背景 1.1 前端自动化测试较少 前端浏览器众多导致页面兼容性问题比较多,另外界面变化比较快,一个月内可能页面改版两三次,这样导致对前端自动化测试较少,大家也不是 ...
- Maven自动FTP远程部署
参照官网文档: https://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html 1.在pom.xml中加入: ...
- abp 依赖注入声明
public class SchedulerManager : ISingletonDependency { private ILogger logger; public SchedulerManag ...
- ospf基础理论
OSPF简介 OSPF(Open Shortest Path First 开放式最短路径优先)协议是IETF为IP网络开发的IGP路由选择协议.它是一种典型的链路状态(link-state)路由协议. ...
- lightgbm调参方法
gridsearchcv: https://www.cnblogs.com/bjwu/p/9307344.html gridsearchcv+lightgbm cv函数调参: https://www. ...
- Spring框架初写
1.Spring的概述 a) Spring是什么 Spring是一个JavaEE轻量级的一站式 Java EE的开发框架. JavaEE: 就是用于开发B/S的程序.(企业级) 轻量级:使用最少代 ...
- C# openfiledialog的使用
文件对话框(FileDialog) 一.打开文件对话框(OpenFileDialog) 1. OpenFileDialog控件有以下基本属性 InitialDirectory 对话框的初始目录Filt ...
- (转)MySQL出现同步延迟有哪些原因?如何解决?
http://oldboy.blog.51cto.com/2561410/1682147----MySQL出现同步延迟有哪些原因?如何解决? 原文:http://www.zjian.me/mysql/ ...
- 如何写出优雅的JavaScript代码 ? && 注释
如何写出优雅的JavaScript代码 ? 之前总结过一篇<如何写出优雅的css代码?>, 但是前一段时间发现自己的js代码写的真的很任性,没有任何的优雅可言,于是这里总结以下写js时应当 ...
- 【数组】Subsets
题目: Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset ...