题目链接

分析一下题意可以得到题目要求的是满足下面这个 公式的不同的i,ji,ji,j的方案数;

即(i2+j2)mod   m=0 (n ≤ i,j≤ n)(i^2+j^2)\mod \ m =0\ ( n\ \leq\ i,j\leq \ n)(i2+j2)mod m=0 (n ≤ i,j≤ n).

当然n2n^2n2是可以解决的,但是数据范围不允许我们这么做,于是我们可以换个思路,如果一个数iii满足 imod  m=0\ i\mod m=0 imodm=0,那么(i+k∗m)(i+k*m)%m(i+k∗m)也必然是等于000的,因为任意一个数xx%mx的结果必然是小于mmm的,于是我们可以m2m^2m2的复杂度来解决这个问题。在mmm的范围内找出所有满足题意的i,ji,ji,j。然后对每一对i,ji,ji,j 进行累加贡献。然后这个问题就解决了。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
LL n,m,ans;
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if((i*i+j*j)%m==0&&i<=n&&j<=n){
LL a=(n-i)/m+1,b=(n-j)/m+1;
if(!i)a--;
if(!j)b--;
ans+=a*b;
}
}
}
cout<<ans<<endl;
return 0;
}

Mail.Ru Cup 2018 Round 3 B. Divide Candies的更多相关文章

  1. [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<= ...

  2. Mail.Ru Cup 2018 Round 3 Solution

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

  3. Mail.Ru Cup 2018 Round 3

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  4. Mail.Ru Cup 2018 Round 2

    A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  5. [codeforces Mail.Ru Cup 2018 Round 1 D][ xor 操作]

    http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题 ...

  6. Mail.Ru Cup 2018 Round 2 Solution

    A. Metro Solved. 题意: 有两条铁轨,都是单向的,一条是从左往右,一条是从右往左,Bob要从第一条轨道的第一个位置出发,Alice的位置处于第s个位置,有火车会行驶在铁轨上,一共有n个 ...

  7. Mail.Ru Cup 2018 Round 1

    A. Elevator or Stairs? 签. #include <bits/stdc++.h> using namespace std; ]; int main() { while ...

  8. Mail.Ru Cup 2018 Round 1 virtual participate记

    因为睡过了只好vp. A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include< ...

  9. Mail.Ru Cup 2018 Round 2C(__gcd)

    #include<bits/stdc++.h>using namespace std;long long mx(long long l1,long long r1,long long l2 ...

随机推荐

  1. c++11の关联容器

    一.关联容器 C++的容器类型可以分为顺序容器和关联容器两大类.对于关联容器,主要有map和set,对于这两种,根据不同的维度,衍生出了8种容器 map                        ...

  2. [已解决]ValueError: row index was 65536, not allowed by .xls format

    报错: ValueError: row index was 65536, not allowed by .xls format 解决方案: xlrd和xlwt处理的是xls文件,单个sheet最大行数 ...

  3. Troubleshooting 'library cache: mutex X' Waits. (Doc ID 1357946.1)

    In this Document   Purpose   Troubleshooting Steps   What is a 'library cache: mutex X' wait?   What ...

  4. RequestMapper

    @RequestMapping(value = "/v1/getAllUrl", method = RequestMethod.POST) public Object getAll ...

  5. 利用 keras_proprecessing.image 扩增自己的遥感数据(多波段)

    1.keras 自带的 keras_proprecessing.image 只支持三种模式图片(color_mode in ['grey', 'RGB', 'RGBA'])的随机扩增. 2.遥感数据除 ...

  6. dos命令的使用

    echo 百度欢迎您 >d:\1.txt F7查看执行过的命令 直接进入 D盘 d: 创建目录 md fox 在fox目录下创建子目录user md fox\user\hello1 进入到use ...

  7. 一些矩阵范数的subgradients

    目录 引 正交不变范数 定理1 定理2 例子:谱范数 例子:核范数 算子范数 定理3 定理4 例子 \(\ell_2\) <Subgradients> Subderivate-wiki S ...

  8. lower_bound( )和upper_bound( )的基本用法

    lower_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于或等于num的数字,找到返回该数字的地址,不存在则返回end.通过返回的地址减去起始地址 ...

  9. linux 基本命令2

    linux没有磁盘的概念,这一点不同于windows,Linux所有的文件系统采用树的结构完成(核心本质)树自然有根节点 也就是linux存在一个根目录,用/表示ls 表示查看命令 我们使用 ls / ...

  10. OSI七层模型的每一层都有哪些协议

    TCP/IP: 数据链路层:ARP,RARP 网络层: IP,ICMP,IGMP 传输层:TCP ,UDP,UGP 应用层:Telnet,FTP,SMTP,SNMP. OSI: 物理层:EIA/TIA ...