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. js 正则常用函数 会正则得永生

    正则表达式作为一种匹配处理字符串的利器在很多语言中都得到了广泛实现和应用,web开发本质上是处理字符串(服务端接受请求处理后拼接字符串作为响应,这在早期的CGI编程中最明显,然后客户端解析字符串进行渲 ...

  2. install sz rz linux

    1◆ ready 2◆ controller component   Xshell 注册码:690313-111999-999313 Xftp 注册码:101210-450789-147200   3 ...

  3. Linux电源管理-Linux regulator framework概述

    前言 1.  什么是regulator?      regulator翻译为"调节器",分为voltage regulator(电压调节器)和current(电流调节器).一般电源 ...

  4. day20 类的约束

    今日所学 : 1 .类的约束 2 .异常处理 try except raise 3. MD5加密 4. 日记处理(不要记,留一份,侧重点再用) 1 .类的约束 1) 写一个父类,父类中的某个方法要抛出 ...

  5. [leetcode整理]

    =======简单 leetcode164 Maximum Gap sort两次 =======有参考 330 Patching Array 98 Validate Binary Search Tre ...

  6. 201621123001《Java程序设计》第1周学习总结

    1. 本周学习总结 认识java的三个层次:java语法 面向对象设计能力 应用 . 学习eclipse创建java文件的方法. 学习markdown的基本语法,了解写博客的几种常用形式. 了解JVM ...

  7. W phase 学习

    W phase 的组成:(相关文献发现W phase适用于6级以上的地震) P, PP,S,SS,SP,PS等等长周期的震相: 它的传播机制和whispering gallery 相似. 从简振理论来 ...

  8. day 32 子进程的开启 及其用法

    开启两种子进程的两种方式# # # 1 传统方式# from multiprocessing import Process# import time# def task(name):# print ( ...

  9. linux下关于PCL(point cloud library)库的安装,三行命令错误的问题

    最近想再看看PCL,所以进行了安装,在之前的接触的过程中,由于之前的网络存在问题,导致以下三个命令: sudo add-apt-repository ppa:v-launchpad-jochen-sp ...

  10. python cookies提取——从字符串到字典(一行Python代码)

    def extract_cookies(cookie): """从浏览器或者request headers中拿到cookie字符串,提取为字典格式的cookies&quo ...