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 ...
随机推荐
- 函数指针使用演示样例(參考Linux-内核代码)
本文有xhz1234(徐洪志)编写,转载请注明出处. http://blog.csdn.net/xhz1234/article/details/36635083 作者:徐洪志 近期阅读Linux-内核 ...
- CAM350 10.5移动和叠层的用法
1.快捷键 EC复制 IMO测量最近距离 UZ放大,缩小尺寸 UC拷 ...
- SpringMVC学习(一):搭建SpringMVC-注解-非注解
文章参考:http://www.cnblogs.com/Sinte-Beuve/p/5730553.html 一.环境搭建: 目录结构: 引用的JAR包: 如果是Maven搭建的话pom.xml配置依 ...
- 啥是Restful?
在Web设计与开发中,经常会看到Restful这个概念.对HTTP没有深入了解的我看到这个,基本一带而过. 其实既然只是概念,理解其中的意思就OK. Restful 1. 一种Web设计/架构方式 2 ...
- Java解析Property文件
在Java项目中一些配置參数保存在Property文件里,这样能保证不改动原代码直接改动Property文件. PropertyParser.java package com.discover.par ...
- LeetCode(70)题解: climbing-stairs
https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps t ...
- wcf服务发布时,目录中没有文件生成
1.删除原有的配置文件
- 九度OJ 1143:Primary Arithmetic(初等数学) (进位)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:616 解决:254 题目描述: Children are taught to add multi-digit numbers from ri ...
- unity导出android项目
1. 2 . 3 选择Google Android Project(若不选则直接导出Apk) Export,Android项目即可导出成功.
- Gradle sync failed: Connection timed out: connect
打开AS的project试图,找到gradle目录下的wrapper下面的gradle wrapper.properities找到: distributionUrl=https\://services ...