题意

题目链接

求满足\(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. Oracle to_char的用法

    The following are number examples for the to_char function. to_char(1210.73, '9999.9') would return ...

  2. Word2Vec原理及代码

    一.Word2Vec简介 Word2Vec 是 Google 于 2013 年开源推出的一款将词表征为实数值向量的高效工具,采用的模型有CBOW(Continuous Bag-Of-Words,连续的 ...

  3. leetcode-840-Magic Squares In Grid

    题目描述: A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each r ...

  4. QuantLib 金融计算——基本组件之 InterestRate 类

    目录 QuantLib 金融计算--基本组件之 InterestRate 类 InterestRate 对象的构造 一些常用的成员函数 如果未做特别说明,文中的程序都是 Python3 代码. Qua ...

  5. windows任务管理器所查的网站

    添加menu   https://blog.csdn.net/u012273127/article/details/71293088 点击菜单打开对话框  https://blog.csdn.net/ ...

  6. Java中HashMap的hash分布策略的简单解释

    趴源码是看到一段不可思议的代码,网上的解释似乎不大令人满意,因此稍微花点时间解读了一下,如有错误请指正 HashMap的桶是这样搞的 // 片段1 static final int hash(Obje ...

  7. [转] spark-submit 提交任务及参数说明

    [From] https://www.cnblogs.com/weiweifeng/p/8073553.html#undefined spark-submit 可以提交任务到 spark 集群执行,也 ...

  8. json对象和数组

    Json数据就是格式化的字符串.c#中如果做为参数调用,类型就是string.1.Json数组 方括号[{ "firstName":"John" , " ...

  9. 关于c#中”ref”和”out”关键字的一些理解

    一. 综述(本文内容大部分来自网络,经本人整理而成,仅供学习参考,不免理解错误,欢迎批评指正) 在c#中,方法的参数传递有四种类型: (1) 传值参数(by value) 传值参数无需额外的修饰符.传 ...

  10. 自定义 checkbox 样式

    前言:最近在做一个网站,为了统一风格,需要自定义checkbox的样式.所以花了点时间参考了 研究了一下.感觉上面的方法略微麻烦.所以自己重新写了下面的代码,欢迎大家指教.同时,感谢w3cplus提供 ...