A - Alyona and Numbers
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
Input6 12Output14Input11 14Output31Input1 5Output1Input3 8Output5Input5 7Output7Input21 21Output88
题意:
输入两个数n,m。从1~n和1~m中各取一个值,使两值相加为5的倍数,求总共有多少种组合。
可从1~n依次取一个值i,并和1~m中的值相加使其和成为5的倍数。
如:6,12时有:1+4,1+9,2+3,2+8,3+2,3+7,3+12...由此我们可见,取值为i时可整除的和的数目为(i+m)/5,可当i>=5时,其本身包含的5的倍数就不能计入总数,如i=6时,和为5就不成立,故总数应减掉i/5。
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main(){
long long n,m;//注意要用long long
while(cin>>n>>m){
long long sum=;
for(int i=;i<=n;i++){//将n从1到n循环
sum+=(m+i)/;
if(i>=)
sum-=i/;
}
cout<<sum<<endl;//输出
}
return ;
}
A - Alyona and Numbers的更多相关文章
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- 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 Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- CF | Alyona and Numbers
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down ...
- CodeForces 682A Alyona and Numbers (水题,数学)
题意:给定两个数 m,n,问你在从1到 n,和从 1到 m中任选两个数加起来是5的倍数,问你有多少个. 析:先计算 m 和 n中有多少个取模5是从0到4的,然后根据排列组合,相乘就得到了小于等于 m ...
- CodeForces 682A
D - Alyona and Numbers Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp
A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- codeforces 381 D Alyona and a tree(倍增)(前缀数组)
Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- Springmvc返回信息乱码解决
恩...基本上所有的配置信息都弄上了,但是还是乱码,最后在方法上面添加了下面的参数,就完美解决了: @RequestMapping(value="/action.action",m ...
- openshifit 安装 redis
http://blog.csdn.net/lsx991947534/article/details/48860537 http://blog.csdn.net/aguangg_6655_la/arti ...
- Python list 和 str 互转
一.list转字符串 命令:''.join(list)其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等如:list = [1, 2, 3, 4, 5]''.join(list) 结果即为 ...
- 关于mongorc.js文件详解
最近阅读了<<mongodb权威指南第二版>>,发现这本书比之前的第一版好,很多地方讲解很详细.下面就翻译下谈下这个文件. 首先,启动shell的时候,mongorc.js文件 ...
- 九度OJ 1117:整数奇偶排序 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3174 解决:932 题目描述: 输入10个整数,彼此以空格分隔.重新排序以后输出(也按空格分隔),要求: 1.先输出其中的奇数,并按从大到 ...
- 初识代码封装工具SWIG(回调Python函数)
这不是我最早使用swig了,之前在写Kynetix的时候就使用了swig为python封装了C语言写的扩展模块.但是当时我对C++还不是很了解,对其中的一些概念也只是拿来直接用,没有理解到底是什么,为 ...
- Qt JSON解析生成笔记
对于这样一段json { "name": "布衣食", "gender": "Male", "age" ...
- AndroidPageObjectTest_Chained.java
以下代码使用ApiDemos-debug.apk进行测试 //这个脚本用于演示PageFactory的功能:链式注解@AndroidFindBys.@IOSFindBys.具体用法参考页面类的代码. ...
- Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分
题目链接:http://codeforces.com/problemset/problem/729/C C. Road to Cinema time limit per test 1 second m ...
- CSU1808 地铁 —— dijkstra变形
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题解:由于中转线路需要花费一定的时间,所以一般的以顶点为研究对象的dijkst ...