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