A - Alyona and Numbers

本文介绍了一个计数问题:从1到n和1到m中各取一个值,使得这两个值之和能被5整除,求所有可能的组合数量。通过分析给出了具体的解决方法和AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ≤ n1 ≤ 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 ≤ n1 ≤ 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

 

题意:

输入两个数n,m。从1~n和1~m中各取一个值,使两值相加为5的倍数,求总共有多少种组合。

 

可从1~n依次取一个值i,并和1~m中的值相加使其和成为5的倍数。

如:6,12时有:1+4,1+9,2+3,2+8,3+2,3+7,3+12...由此我们可见,取值为i时可整除的和的数目为(i+m)/5,可当i>=5时,其本身包含的5的倍数就不能计入总数,如i=6时,和为5就不成立,故总数应减掉i/5。

 

附AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 int main(){
 8     long long n,m;//注意要用long long 
 9     while(cin>>n>>m){
10     long long sum=0; 
11         for(int i=1;i<=n;i++){//将n从1到n循环 
12         sum+=(m+i)/5;
13         if(i>=5)
14         sum-=i/5;
15     } 
16     cout<<sum<<endl;//输出 
17     }
18     return 0;
19 }

 

转载于:https://www.cnblogs.com/Kiven5197/p/5659165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值