D - Alyona and Numbers

Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

CodeForces 682A

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

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

Hint

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.

AC代码:

#include <stdio.h>
int main()
{
int n,m,i;
long long sum=0;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
sum+=((m+i)/5-i/5);
printf("%lld",sum);
return 0;
}

题意:给出两个整数n,m;两组整数从1~n和1~m,交错相加,如果两个数相加是5的倍数,则给计数器加1,最后总的输出计数器的大小。

错误点在于:很多人使用外循环n和内循环m,这样的话算法太复杂,程序超时,无法AC,故根据他们余数的特点,找出减少运算量的方法

即:(m+i)/5-i/5,还有注意sum的范围,超出int范围,使用long long

zsy:

AC代码:

#include<stdio.h>
int main()
{
int n,m,i;
long long count=0;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
count+=((m+i)/5-i/5);
}
printf("%lld\n",count);
return 0;
}

CodeForces 682A的更多相关文章

  1. CodeForces 682A Alyona and Numbers (水题)

    Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...

  2. CodeForces 682A Alyona and Numbers (水题,数学)

    题意:给定两个数 m,n,问你在从1到 n,和从 1到 m中任选两个数加起来是5的倍数,问你有多少个. 析:先计算 m 和 n中有多少个取模5是从0到4的,然后根据排列组合,相乘就得到了小于等于 m ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. MySQL批量修改字符集

    统一将字符字符集变成utf8_general_ci,已测试. DROP PROCEDURE IF EXISTS `chanageCharSet`; CREATE PROCEDURE `chanageC ...

  2. memory prefix pre,pro,penta,pseudo out _p 1

    1● pre 前的,预先   2● pro 在前,很多,赞同       3● penta 5,五     4● pseaudo   伪,假 pseudo  

  3. MyEclipse常用设置和快捷键

    Java快捷键 1.注释快捷键 先敲/  再敲两个**     Enter 回车 2.system.out.println(); 常用设置 [子类继承父类] [编码字体设置] 删除当前行:ctrl+d ...

  4. .net core 在扩展中使用接口实例之IServiceProvider

    在.net core 2.0中,我们使用的对象实例大多数都是通过构造函数依赖注入进来的,但那是在一般的类中使用. 如果需要在静态/扩展类中使用某些服务类的对象实例,可以使用如下方式: 1.新建一个Se ...

  5. Linux使用定时器timerfd 和 eventfd接口实现进程线程通信

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  6. TLS反调试

    0x01 TLS反调试简介 TLS(Thread Local Storage)原本的目的是解决多线程程序中变量同步的问题.线程本身有独立于其他线程的栈空间,因此线程中的局部变量不用考虑同步问题.多线程 ...

  7. 20165326 Linux系统安装及学习

    Linux安装及学习 一.系统安装 此处选取安装的材料:LInux5.2.6 & ubuntu16.04.03 linux的安装:十分顺利,从官网选取了最新版本,根据图文步骤安装成功. ubu ...

  8. Android:如何获取屏幕的宽高

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); DisplayMet ...

  9. 点击图片或者鼠标放上hover .图片变大. 1)可以使用css中的transition, transform 2) 预先设置一个 弹出div. 3)弹出层 alert ; 4) 浏览器的宽度document.documentElement.clientWidth || document.body.clientWidth

    变大: 方法一: 利用css属性. 鼠标放上 hover放大几倍. .kecheng_02_cell_content img { /*width: 100px; height: 133px;*/ wi ...

  10. scrapy框架发送post请求

    注:scrapy框架默认发送get请求 1.想要发送post请求,那么推荐使用‘scrapy.FormRequest’方法.可以方便的制定表单数据.request = scrapy.FormReque ...