CSU 1803 2016
来源:互联网 发布:java判断链表是否有环 编辑:程序博客网 时间:2024/05/22 03:01
Description
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:
1≤a≤n,1≤b≤m;
a×b 是 2016 的倍数。
Input
输入包含不超过 30 组数据。
每组数据包含两个整数 n,m (1≤n,m≤109).
Output
对于每组数据,输出一个整数表示满足条件的数量。
Sample Input
32 63
2016 2016
1000000000 1000000000
Sample Output
1
30576
7523146895502644
解法: a*b是2016的倍数,直接枚举不可能,容易想到用2个长度为2016的数组记录n和m模上2016为i的个
数,然后暴力枚举就可以了。复杂度O(2016^2)
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 2020;int a[maxn], b[maxn];LL n, m;int main(){ while(scanf("%lld%lld", &n,&m)!=EOF) { for(int i=0; i<2016; i++){ a[i]=n/2016; if(n%2016>=i){ a[i]++; } b[i]=m/2016; if(m%2016>=i){ b[i]++; } } a[0]--; b[0]--; LL ans=0; for(int i=0; i<2016; i++){ for(int j=0; j<2016; j++){ if(i*j%2016==0){ ans+=1LL*a[i]*b[j]; } } } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- CSU 1803 2016
- [CSU 1803 2016]数学
- CSU 1803 2016 【枚举】
- CSU 1803: 2016
- CSU 1803 2016(数论)
- CSU 1803 2016
- CSU 1803: 2016 (省赛真题)
- CSU 1803 2016
- CSU 1803: 2016
- CSU 1803 2016(思维)
- CSU 1803:2016解题报告
- 2016 CSU 1803 (思路)
- CSU 1803:2016(数论)
- CSU 1803
- csu 1803 2016 2016湖南省赛 A
- CSU 1803 2016 (逆向思维)
- CSU-1803: 2016 ,同余定理!
- CSU 1803 2016 (数论+思路)
- 设计模式(1)-Abstract Factory 抽象工厂模式
- 20170531学习笔记整理
- TCP/IP三次握手
- C++菱形继承
- raphael.js arrow颜色修改
- CSU 1803 2016
- 对double类型的数据 进行4 舍5入
- centos中使用yum下载 RPM 包及其所有依赖
- 梯度提升树(GBDT)原理小结
- Android Butterknife 8.4.0 使用方法总结
- css3选择器--分类(一)
- 关于java中char,byte,short的移位操作
- Linux内核中断底半部处理--内核微线程
- Apache Hive2.1.1安装部署