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. 微信支付 php兼容问题

    总结: php7 已删除 HTTP_RAW_POST_DATA  获取时需要file_get_contents("php://input"); 下面的是兼容方法. //存储微信的回 ...

  2. 原 spring-boot工程中,jpa下hibernate的ddl-auto的各种属性

    jpa:  hibernate:    ddl-auto: create ddl-auto:create----每次运行该程序,没有表格会新建表格,表内有数据会清空 ddl-auto:create-d ...

  3. vbox 虚拟机添加usb

    先装扩展包. vbox 所在的用户组比如要包括当前用户才行. 查看当前用户名:sharl@sharl-laptop:~$ whoamisharl 查看vbox 所在的组:sharl@sharl-lap ...

  4. 研究Duilib的实现结构

    第一步:调用RegisterClassEx(): 第二步:调用CreateWindowEx() 第三步:调用ShowWindow(),同时启动消息循环 说明: 1.RegisterClass,Regi ...

  5. Uva LV 2995 Image Is Everything 模拟,坐标映射,视图映射 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  6. 遍历所有子物体中renderer(渲染器)中的material(材质)

    //得到所有可渲染的子物体Renderer[] rds = transform.GetComponentsInChildren<Renderer>();//逐一遍历他的子物体中的Rende ...

  7. Struts2的基础知识

    Struts2属于MVC框架 Struts2的优点: 1.侵入性低 2.提供了拦截器,可以利用拦截器进行AOP编程 3.提供了类型转换器 4.支持多种表示层技术:jsp,freeMarker,Vele ...

  8. word-wrap与break-word属性的区别

    共同点 word-wrap:break-word与word-break:break-all都能把长单词强行断句 不同点 word-wrap:break-word会首先起一个新行来放置长单词,新的行还是 ...

  9. tomcat 启动Spring boot 项目

    SpringBoot 项目如何在tomcat容器中运行 1.相关连接: https://blog.csdn.net/u010598360/article/details/78789197/ 2.修改打 ...

  10. Java基础知识补充

    基础知识总结: 学习了一段时间,重新看了孤傲苍狼的博客,对一些知识有了新的理解. unicode: 全球的文字放到计算机里面表示全是0和1,Unicode是统一了全世界国家文字的一种编码方式,用这样的 ...