Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers
题目连接:
http://www.codeforces.com/contest/682/problem/A
Description
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 12
Sample Output
14
Hint
题意
给你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;
}
Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题的更多相关文章
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- HDU 6057 Kanade's convolution
题目链接:HDU-6057 题意: 思路:先按照官方题解推导出下面的式子: 现在唯一的问题就是怎么解决[bit(x)-bit(y)=bit(k)]的问题. 我们定义\( F(A,k)_{i}=\lef ...
- K/V式枚举
public enum OType { LOGIN { public String getDesc() { return "登录"; } }, ADD { public Strin ...
- java 读取配置文件类
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; im ...
- poj1095
题意:给出n,要求输出第n个二叉树,二叉树编号规则如下图所示: 分析:g[i]表示有i个节点的二叉树,有多少种.f[i][j]表示有i个节点,且左子树有j个节点的树有多少种. sumg[i]表示g数组 ...
- Nginx - upstream 模块及参数测试
目录 - 1. 前言- 2. 配置示例及指令说明 - 2.1 配置示例 - 2.2 指令 - 2.3 upstream相关变量- 3. 参数配置及测试 - 3.1 max_fa ...
- java基础39 增强for循环(也叫foreach循环)
增强for循环是jdk1.5出现的新功能 1.增强for循环的作用 简化了迭代器的书写格式(注意:增强for循环底层还是使用了迭代器遍历) 2.增强for循环的格式 for(数据类型 变量名:遍历的目 ...
- git —— 标签
标签:为分支添加一个可读标识. 1.创建标签 操作步骤: 切换到需要打标签的分支上 $ git branch $ git checkout master 为当前分支新增一个标签 $ git tag v ...
- C++ 虚函数及重载、重定义、重写
#include<iostream> usingnamespace std; class BASE { public: BASE()=default; BASE(int publicVal ...
- sql server 2000系统表sysproperties在SQL 2008中无效的问题
Sqlserver有一个扩展属性系统表sysproperties,因为只接触过MSSQL2005及以后的版本,在生产库2008版本及联机文档上搜了下都找不到这个系统表,后来发现这个系统表在2005版本 ...
- 20155225 2016-2017-2 《Java程序设计》第六周学习总结
20155225 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 java的输入输出系统 在重新指定标准输入输出时不同: 重新指定标准输入为文档输入时,是这样 ...