2016湖南省赛----A 2016 (同余定理)
2016湖南省赛----A 2016 (同余定理)
Description
Input
Output
Sample Input
32 63
2016 2016
1000000000 1000000000
Sample Output
1
30576
7523146895502644 思路:
同余定理 : 设 a%2016 = c1 , b%2016 = c2, 若,c1*c2%2016 == 0,则 a*b%2016 == 0;
根据余数不同可将 1~n 与 1~m 按余数进行分类,统计 1~n 与 1~m 对2016求余 各余数的个数,分别为 a[1],a[2] .....a[2016],
b[1],b[2]......b[2016]。根据同于定理,若 i*j%2016 == 0; 则可知余数为i,与余数为j的数相乘为2016的倍数,且共有a[i]*b[j]
种方式。
具体实现如下:
#include <iostream>
#include <stdio.h>
#include <stdio.h>
using namespace std; long long a[];
long long b[];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
memset(a,,sizeof(a));
memset(b,,sizeof(b));
// 计算 1~n 中对2016求余 各余数的个数
int c = n/;
for(int i=;i<=;i++)
a[i] = c;
n = n%;
for(int i = ;i<=n;i++)
a[i]++;
// 计算 1~m 中对2016求余 各余数的个数
int d = m/;
for(int i = ;i<=;i++)
b[i] = d;
m = m%;
for(int i = ;i<=m;i++)
b[i]++;
long long sum = ;
for(int i = ;i<=;i++)
for(int j = ;j<=;j++)
if(i*j% == )
sum+=a[i]*b[j];
printf("%lld\n",sum);
}
return ;
}
2016湖南省赛----A 2016 (同余定理)的更多相关文章
- 2016湖南省赛 A 2016 题解(同余)
题目链接 题目大意 给出正整数 n 和 m,统计满足以下条件的正整数对 (a, b) 的数量: 1<=a<=n 1<=b<=m a*b%2016=0 题目思路 我本来以为是容斥 ...
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
- 2016湖南省赛 I Tree Intersection(线段树合并,树链剖分)
2016湖南省赛 I Tree Intersection(线段树合并,树链剖分) 传送门:https://ac.nowcoder.com/acm/contest/1112/I 题意: 给你一个n个结点 ...
- 2016湖南省赛--A题--2016
2016 [TOC] Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input ...
- 第十二届湖南省赛 A - 2016 ( 数学,同余转换)
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 ...
- 2016湖南省赛 [Cloned]
A.2016 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数 ...
- 十二届 - CSU 1803 :2016(同余定理)
题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所 ...
- CSU 1803 2016 湖南省2016省赛
1803: 2016 Submit Page Summary Time Limit: 5 Sec Memory Limit: 128 Mb Submitted: 1416 ...
- 2016 湖南省省赛 Problem A: 2016
Problem A: 2016 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 296 Solved: 171 Description 给出正整数 n ...
随机推荐
- HDU 3001 Travelling (状压DP,3进制)
题意: 给出n<=10个点,有m条边的无向图.问:可以从任意点出发,至多经过同一个点2次,遍历所有点的最小费用? 思路: 本题就是要卡你的内存,由于至多可经过同一个点2次,所以只能用3进制来表示 ...
- [Git]使用Git上传本地项目,并同步到Github上
第一步:先要在github.com中创建一个仓库(New Repository). 第二步,打开Git Bash ① git init [+仓库名]:初始化仓库,执行之后可以在指定的仓库存放地上面看到 ...
- UVA 11093 Just Finish it up 环形跑道 (贪心)
有一个环形跑道,上面有n个加油站,到i号加油站可以加pi的油,跑到下一站要花费qi的油,起点任意选,问是否有一个起点可跑完整个跑道. 从i开始跑,如果遇到某个站j不能跑了,那么从i到j之间的站开始跑, ...
- 2018.5.14 PHP基础学习
1.使用PHP输出HTML 使用PHP输出一个表格,并且通过style标签改变字体 <!--思考与练习--> <style type="text/css"> ...
- 两个有序数列,求中间值 Median of Two Sorted Arrays
原题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...
- PAT (Basic Level) Practise (中文)- 1014. 福尔摩斯的约会 (20)
http://www.patest.cn/contests/pat-b-practise/1014 1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 ...
- atomic nonatomic区别
摘要 atomic和nonatomic区别用来决定编译器生成的getter和setter是否为原子操作.atomic提供多线程安全,是描述该变量是否支持多线程的同步访问,如果选择了atomic 那么就 ...
- NSRegularExpression 使用
需求: // 后台返回的某个实体 reminder = { cost = , type = , template = 可免费做某事{time}分钟,超过将按{cost}K元收费, time = } t ...
- git 指令记录
由于之前一直用svn 用git也是用图形化的工具 还是要了解一下git指令 因为都是版本控制工具 有很多相似之处 所以理解起来也比较轻松 仓库: github上面的项目 工作目录下面的所有文件都不外乎 ...
- 『jQuery』.html(),.text()和.val()的概述及使用--2015-08-11
如何使用jQuery中的.html(),.text()和.val()三种方法,用于读取,修改元素的html结构,元素的文本内容,以及表单元素的value值的方法 本节内容主要介绍的是如何使用jQu ...