CF | Alyona and Numbers
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.
Example
6 12
14
11 14
31
1 5
1
3 8
5
5 7
7
21 21
88
Note
Following pairs are suitable in the first sample case:
- for x = 1 fits y equal to 4 or 9;
- for x = 2 fits y equal to 3 or 8;
- for x = 3 fits y equal to 2, 7 or 12;
- for x = 4 fits y equal to 1, 6 or 11;
- for x = 5 fits y equal to 5 or 10;
- for x = 6 fits y equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
#include<bits/stdc++.h>
using namespace std; int main()
{
int n,m,t,count1,count2,temp;
while(cin>>n>>m) {
long long int ans = ;
if(n > m) {
t = n;
n = m;
m = t;
}
count1 = m / ; // 求出有多少组 (1 2 3 4 5)
count2 = m % ; // 求出剩余多少个数 for(int i = ; i <= n; i++)
{
ans += count1; //每一个数在一个循环组有能够找到一个相加模5等于0的数
temp = i % ; //temp i 在 循环组的位置
if((-temp )<= count2 && count2 != ) //根据循环组的内规律进行匹配 1--4 2--3
{
ans++;
}
} cout<<ans<<endl;
} return ;
}
CF | Alyona and Numbers的更多相关文章
- A. Alyona and Numbers(CF ROUND 358 DIV2)
A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- CF | Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...
- A - Alyona and Numbers
Description After finishing eating her bun, Alyona came up with two integers n and m. She decided to ...
- CF D. Beautiful numbers (数位dp)
http://codeforces.com/problemset/problem/55/D Beautiful Numbers : 这个数能整除它的全部位上非零整数.问[l,r]之间的Beautifu ...
- 【数位dp】CF 55D Beautiful numbers
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- 数位DP CF 55D Beautiful numbers
题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...
随机推荐
- Python REST
Django REST framework 1. 什么是REST REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译 ...
- Python的字典和JSON
Python的字典和JSON在表现形式上非常相似 #这是Python中的一个字典 dic = { 'str': 'this is a string', 'list': [1, 2, 'a', 'b'] ...
- spring加载xml的六种方式
因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装入系统,这就需要利用Spring去动态加载某一位置下的配置文件,所以就总结了下Spring中加载xml配置文件的方式,我总结的有6 ...
- [LeetCode] Count Different Palindromic Subsequences 计数不同的回文子序列的个数
Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...
- python--元祖和字典
一.1:元祖:tuple 在python中,元祖也是一个list, 它和list的区别是list中的元素可以修改,而元祖中的元素不可以修改. 2:元祖的定义:用小括号() 二.1.字典 字典全程d ...
- bzoj4896 补退选
Description X是T大的一名老师,每年他都要教授许多学生基础的C++知识.在T大,每个学生在每学期的开学前都需要选课,每 次选课一共分为三个阶段:预选,正选,补退选:其中"补退选& ...
- [SCOI2009]围豆豆
Description Input 第一行两个整数N和M,为矩阵的边长. 第二行一个整数D,为豆子的总个数. 第三行包含D个整数V1到VD,分别为每颗豆子的分值. 接着N行有一个N×M的字符矩阵来描述 ...
- POJ 2289(多重匹配+二分)
POJ 2289(多重匹配+二分) 把n个人,分到m个组中.题目给出每一个人可以被分到的那些组.要求分配完毕后,最大的那一个组的人数最小. 用二分查找来枚举. #include<iostream ...
- hdu 5131(2014 广州—模拟)
题意:给你n个人以及他们的杀人数.先按杀人数从大到小排名输出,然后是一些询问 一个人名,①输出杀人数比他大的人数和+1:②如果有人杀人数和他一样而且名字的字典序比他小,输出人数+1,没有则无视. #i ...
- make cmake gcc 间的关系
看了一些关于make cmake gcc间关系的帖子,其中这一篇简单明了. 作者:辉常哥链接:https://www.zhihu.com/question/36609459/answer/89743 ...