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索引引起的死锁

    提到索引,首先想到的是效率提高,查询速度提升,不知不觉都会有一种心理趋向,管它三七二十一,先上个索引提高一下效率..但是索引其实也是暗藏杀机的... 今天压测带优化项目,开着Jmeter高并发访问项目 ...

  2. Java IO流01-总叙

     Java IO包体系结构图: 1.流式部分――IO的主体部分: 2.非流式部分——主要包含一些辅助流式部分的类,如:File类.RandomAccessFile类和FileDescriptor等类: ...

  3. error TS2304: Cannot find name 'Promise' && TS2307: Cannot find module '**'

    error TS2304: Cannot find name 'Promise' 解决方法:在编译选项中加入"target":"es6" { "ver ...

  4. css3 居中(推荐弹性盒模型方式)

    参考  http://www.zhihu.com/question/20774514 http://caibaojian.com/demo/flexbox/align-items.html 例子:ht ...

  5. 1.DNS基础及域名系统架构

    一.域名: IP地址往往难以记忆,所以我们一般使用域名进行管理 www.LinuxCast.net 1.严格的域名最后还有一个".",但一般省略不写 2.域名分为三个部分,用&qu ...

  6. .net core webapi 配置swagger调试界面

    一.创建一个.net core webapi的项目: 二.在nuget程序包管理器控制台输入  Install-Package Swashbuckle -version 6.0.0-beta902   ...

  7. 类型重命名 typedef

    所谓数据重命名就是给数据类型起一个新的名字,比如int 这个数据类型,可以给他起一个新的名字叫 my int.他俩的用法.特点.属性等是一模一样,仅仅名字不同而已. 作用:1,增加代码的可读性.2,让 ...

  8. 4.6 C++抽象基类和纯虚成员函数

    参考:http://www.weixueyuan.net/view/6376.html 总结: 在C++中,可以通过抽象基类来实现公共接口 纯虚成员函数没有函数体,只有函数声明,在纯虚函数声明结尾加上 ...

  9. 2.19 C++友元函数和友元类

    参考: http://www.weixueyuan.net/view/6350.html 总结: 借助friend关键字将其声明为友元函数,结果,在display函数体内,我们就能访问private属 ...

  10. python笔记4-if..elif-else条件语句

    python中条件判断使用if else来判断,多分支的话使用if elif ... else,也就是如果怎么怎么样就怎么怎么样,否则就怎么怎么这样,格式如下: #if是布尔类型判断,1个是真1个是假 ...