Codeforces Round #358 (Div. 2) A. Alyona and Numbers
2016-06-21 15:59
495 查看
题目连接:
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 howmany 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
14题意:1<=a<=n,1<=b<=m,求a+b能整除5的方案数
思路:直接枚举5的倍数就好了
ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int a=min(n,m),b=max(n,m);
ll ans=0;
for(int i=5;i<=n+m;i+=5)
{
if(i<=a)
ans+=i-1;
else if(i>a&&i<=b)
ans+=a;
else
ans+=(a-i+b+1);
}
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- IT十八掌作业_java基础第十四天_IO
- openstack 网络
- 关于项目配置、链接库冲突、main参数输入
- 树莓派 自身摄像头的opencv调用
- ExpandableListView(可展开的列表组件)的说明以及其用法
- Jenkins2 - 下载与启动
- 启用新博客 http://taney.coding.me , 欢迎访问!
- redmine慢---提速方法
- constexpr变量
- android中的activity跳转动画
- oracle 中的group by ,having 和order by
- 如何设计好的RESTful API之安全性
- Android深度系列一slidingmenu事件处理流程
- 顶层const
- 1404 I-Keyboard(dp+输出最优解)
- 简析.NET Core 以及与 .NET Framework的关系
- HTML表单提交
- unity脚本矩阵和shader内置矩阵区别联系 思考和梳理
- 面向对象语言(如Java)中:基本类型与对象在存储和参数传递上的区别
- 吃冰棒也能中暑(我没看懂)