http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803

Solution:

考虑两个数x,y乘积%2016=0

x×y≡0(MOD 2016)

x=p1×2016+q1

y=p2×2016+q2

x×y=(p1×2016+q1)×(p2×2016+q2)=2016^2×p1p2+2016(p1q2+q1p2)+p1p2≡0(MOD 2016)

实际上就转化为余数乘积取模=0,预处理没两个余数乘积是否mod2016=0

统计答案两个余数出现的个数相乘即可(注意特判0不能选)

复杂度:O(2016^2)

// <1803.cpp> - Wed Oct 19 08:25:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 2016
#define src(x,n) (n/MOD+(x!=0?(n%MOD>=x):0))
using namespace std;
typedef long long LL;
vector<pair<int,int> >a;
int main()
{
freopen("1803.in","r",stdin);
freopen("1803.out","w",stdout);
for(int i=;i<MOD;i++)
for(int j=;j<MOD;j++)
if((i*j)%MOD==)
a.push_back(make_pair(i,j));
int n,m,to=a.size();
while(~scanf("%d%d",&n,&m)){
LL ans=;
for(int i=;i<to;i++)
ans+=1LL*src(a[i].first,n)*src(a[i].second,m);
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. 用margin还是padding
  2. SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)之间区别
  3. [IDEA] IDEA 集成PlantUML
  4. Linux终端杀手、程序员利器-Tmux
  5. jquery使用淘宝接口跨域查询手机号码归属地实例
  6. TRUNCATE与 DELETE
  7. android操作文件
  8. BITED数学建模七日谈之六:组队建议和比赛流程建议
  9. 如何测试mysql是否安装成功
  10. Oracle EBS-SQL (PO-11):检查采购订单退货数.sql
  11. YAML书写规范
  12. attr与prop html与text
  13. Java中Integer和String浅谈
  14. js★★★【面向对象的使用方法】*****************★★★★ 相当重要
  15. [jzoj]1383.奇怪的问题
  16. 大数据学习笔记1-大数据处理架构Hadoop
  17. 解决ArrayList线程不安全
  18. gedit emacs
  19. JVM的自愈能力
  20. input文本框禁止修改文本&mdash;&mdash;disabled和readonly属性的作用及区别

热门文章

  1. 零基础入门学习Python(17)--函数:Python的乐高积木
  2. docker push
  3. 利用端口转发来访问virtualbox虚拟机centos6的jupyter notebook
  4. 常见的Redis问题?
  5. Python:socket实现ftp程序
  6. MySQL Connector/Python 接口 (三)
  7. UVA 253 Cube painting(枚举 模拟)
  8. 添物不花钱学JavaEE(基础篇)-JSP
  9. 动态规划之最长公共子序列(LCS)
  10. [luoguP1472] 奶牛家谱 Cow Pedigrees(DP)