Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
2016-06-18 09:09
567 查看
A. Alyona and Numbers
题目连接:
http://www.codeforces.com/contest/682/problem/ADescription
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.
As usual, Alyona has some troubles and asks you to help.
Input
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).Output
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.Sample Input
6 12Sample Output
14Hint
题意
给你n,m。然后告诉你1<=x<=n,1<=y<=m然后问你(x+y)%5=0的方案有多少种
题解:
考虑余数。两个余数之和为0,那么有0+0,1+4,2+3,3+2,4+1这么五种组合,我可以O(n)或者O(5)统计出每个数的余数为i的有多少个。
然后再O(5)的求解答案就好了。
代码
#include<bits/stdc++.h> using namespace std; long long num1[5]; long long num2[5]; int main() { long long n,m; cin>>n>>m; for(int i=0;i<5;i++) { num1[i]=n/5; if(n%5>=i)num1[i]++; num2[i]=m/5; if(m%5>=i)num2[i]++; } num1[0]--,num2[0]--; long long ans = 0; ans = num1[0]*num2[0]+num1[1]*num2[4]+num1[2]*num2[3]+num1[3]*num2[2]+num1[4]*num2[1]; cout<<ans<<endl; }
相关文章推荐
- HackerRank "Square Subsequences" !!!
- mysql-bin系列日志文件导致linux vps磁盘占满及解决办法
- 使用phpexcel解析Excel数据表并存储到数据库中全过程_PHP_thinkphp_cmf
- 字符串的排列29
- 关于Solr6.0中solrj使用简单例子
- HDU1113 Word Amalgamation
- 互联网协议入门(一)
- eclipse如何创建web项目
- 给 Android 开发者的 RxJava 详解
- Mac MAMP Yaf
- 正则表达式re模块
- 编译提示"_sqlite3_column_int", referenced from: 错误 ---swift中添加sqlite报错
- C语言常用数学函数及其用法
- ~(^_^)~~The first day.
- ACM4-1003
- SSLDOS攻击神器---THC-SSL-DOS 使用笔记
- 机器学习之KNN(K近邻)
- mybatis_user_guide(2)mybatis3.4.0快速入门
- Deep Learning(深度学习)之(五)神经网络训练中的高效BP(反向传播算法)
- SAP SD定价技术分析