A. Alyona and Numbers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

input

6 12

output

14

input

11 14

output

31

input

1 5

output

1

input

3 8

output

5

input

5 7

output

7

input

21 21

output

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.

题目链接:http://codeforces.com/contest/682/problem/A

题意: 给你n和m个数,让你从1 - n 和 1-m 中分别取一个数,组成一个数对,求有多少个数对和为5的倍数。

因为今天一天连续好几个A题都是一路暴力过的,所以这道题想也没想,写了个O(n^2)的算法,TLE了,一开始看错n m取值范围,以为合理优化暴力还是能过的,仔细一看发现必须换方法了。

于是想办法用一层循环做,

想了半天想出一个最蠢的打表……

#include<iostream>

using namespace std;

void swap( int &a , int &b)

{

int temp;

temp=a;

a=b;

b=temp;

return ;

}

int main()

{

int n,m;

cin >> n >> m ;

long long int ans = 0 ;

if( n > m)

swap(n,m);

int unit  = m % 10 ;

for ( int i = 1 ; i <=n ; i++)

{

if( i % 10 == 1 ) ans+=( ( unit >= 4 ) ? 1 : 0 ) + ( ( unit >=9 ) ? 1 : 0 ) + 2* (m / 10 );

if( i % 10 == 2 ) ans+=( ( unit >= 3 ) ? 1 : 0 ) + ( ( unit >=8 ) ? 1 : 0 ) + 2*(m / 10) ;

if( i % 10 == 3 ) ans+=( ( unit >= 2 ) ? 1 : 0 ) + ( ( unit >=7 ) ? 1 : 0 ) + 2*(m / 10) ;

if( i % 10 == 4 ) ans+=( ( unit >= 1 ) ? 1 : 0 ) + ( ( unit >=6 ) ? 1 : 0 ) + 2*(m / 10 );

if( i % 10 == 5 ) ans+= ( ( unit >=5 ) ? 1 : 0 ) + 2*( m / 10 ) ;

if( i % 10 == 6 ) ans+=( ( unit >= 4 ) ? 1 : 0 ) + ( ( unit >=9 ) ? 1 : 0 ) + 2* ( m / 10 );

if( i % 10 == 7 ) ans+=( ( unit >= 3 ) ? 1 : 0 ) + ( ( unit >=8 ) ? 1 : 0 ) + 2*(m / 10 );

if( i % 10 == 8 ) ans+=( ( unit >= 2 ) ? 1 : 0 ) + ( ( unit >=7 ) ? 1 : 0 ) + 2*(m / 10 );

if( i % 10 == 9 ) ans+=( ( unit >= 1 ) ? 1 : 0 ) + ( ( unit >= 6 ) ? 1 : 0) + 2*(m / 10 ) ;

if( i % 10 == 0 ) ans+=( ( unit >= 5 ) ? 1 : 0 ) + 2 * (m / 10) ;

}

cout << ans << endl ;

return 0 ;

}

然后觉得这样写太蠢了,而且我还因为运算优先级问

题WA了好几次就更蠢了(比如m / 2 没加括号,对于m > 5 且 m < 9的情况会有问题),于是搜了一下别人的题解

发现这样一个写法,代码如下:

#include<iostream>

using namespace std;

int main()

{

int n , m ;

long long int ans = 0  ;

cin >> n >>  m;

for( int i = 1 ; i <= n ; i++)

{

ans+= ( i + m ) / 5 - i / 5 ;

}

cout << ans << endl ;

return 0 ; 

}

原理: 对于第i个数,只要看他和m相加之后有多少个5的倍数就是答案,需要注意的是如果i本身大于5,需要减去那一部分,如i=15的时候,5的倍数 5 10 1 5 这三个数就不能考虑了……

自己好蠢。

A. Alyona and Numbers(CF ROUND 358 DIV2)的更多相关文章

  1. CF Round #580(div2)题解报告

    CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...

  2. CF round #622 (div2)

    CF Round 622 div2 A.简单模拟 B.数学 题意: 某人A参加一个比赛,共n人参加,有两轮,给定这两轮的名次x,y,总排名记为两轮排名和x+y,此值越小名次越前,并且对于与A同分者而言 ...

  3. [CF Round #295 div2] C. DNA Alignment 【观察与思考0.0】

    题目链接:C. DNA Alignment 题目大意就不写了,因为叙述会比较麻烦..还是直接看英文题面吧. 题目分析 经过观察与思考,可以发现,构造的串 T 的每一个字符都与给定串 S 的每一个字符匹 ...

  4. [CF Round #294 div2] E. A and B and Lecture Rooms 【树上倍增】

    题目链接:E. A and B and Lecture Rooms 题目大意 给定一颗节点数10^5的树,有10^5个询问,每次询问树上到xi, yi这两个点距离相等的点有多少个. 题目分析 若 x= ...

  5. [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】

    题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...

  6. A. Grasshopper And the String(CF ROUND 378 DIV2)

    A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes input ...

  7. CF Round#436 div2

    额,这次的题目其实挺智障的.所以通过这次比赛,我也发现了自己是一个智障.... 不说太多,说多是泪... A. Fair Game 题意:给你一个数组,看你能否把它均分为两个所有元素均相同的子数组. ...

  8. CF Round #569 Div2(contest1180)

    比赛链接:http://codeforces.com/contest/1180 Problem A 题意:给出n,问方块数.看图理解... Solution: 找一找规律就可以了,发现方块数为2n*( ...

  9. CF Round #687 Div2 简要题解

    题面 A 可以发现,最远的几个人一定是 \((1, 1), (1, m), (n, 1), (n, m)\) 中的一个,直接计算即可. B 注意到颜色数量很少,直接暴力枚举最终的颜色后模拟即可. C ...

随机推荐

  1. Android消息推送之GCM方式(一)

    <声明> 转载请保留本来源地址: http://blog.csdn.net/wzg_1987/article/details/9140371 首先,你需要使用一个谷歌账号登录谷歌Api控制 ...

  2. 【入门】安装Elasticsearch5.0 部署Head插件

    部署5.0版本的ES 5.0版本的ES跟之前的版本最大的不同之处就是多了很多环境的校验,比如jdk,max-files等等. 设置内核参数 vi /etc/sysctl.conf # 增加下面的内容 ...

  3. DroidPlugin插件化开发

    360手机助手使用的 DroidPlugin,它是360手机助手团队在Android系统上实现了一种插件机制.它可以在无需安装.修改的情况下运行APK文件,此机制对改进大型APP的架构,实现多团队协作 ...

  4. ng1笔记

    AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一个 AngularJS 应用程序. ng-model 指令把元素值(比如输入域的值)绑定到应用程序. ...

  5. SDN理解:云数据中心底层网络架构

    目录 - 目录 - 云数据中心流量类型 - NSX整体网络结构 - 管理网络(API网络) - 租户网络 - 外联网络 - 存储网络 - openstack整体网络结构 - 管理网络:(上图中蓝线) ...

  6. Python快捷键

    IDLE默认不能显示行号,使用ALT+G 跳到对应行号,在右下角有显示光标所在行.列. ALT+P  上一个历史输入内容. ALT+N 下一个历史输入内容. IDLE中按F5可以运行代码.

  7. break位于内循环。作用于外循环

    outer:for(int i = 0; i < 4; ++i)  {       inner:for(int j = 0; j < 4; ++j)       {           S ...

  8. CSU 1810 Reverse

    湖南省第十二届大学生计算机程序设计竞赛$H$题 规律,递推. 这种问题一看就有规律.可以按位统计对答案的贡献.即第$1$位对答案作出了多少贡献,第$2$位对答案作出了多少贡献.....累加和就是答案. ...

  9. iOS程序崩溃相关的处理办法

    一.bug追踪 1.捕获异常:Exception breakpoint 步骤: 2.终止调用:Symbolic breakpoint 步骤:前两步和一 基本是一样的,不截图了,只是在第二步选择的时候选 ...

  10. [河南省ACM省赛-第三届] 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...