有关7的倍数问题:

题目如下:

链接:https://ac.nowcoder.com/acm/contest/301/A
来源:牛客网
 

小乐乐得知一周有7天之后就对7产生了兴趣。

小乐乐得到了两堆数字数字时连续的。

第一堆包含[1,n]n个数字,第二堆包含[1,m]m个数字。
小乐乐想要从两堆中各挑选出一个整数x,y,使得x,y的和为7的倍数。

请问小乐乐有多少种组合的方式。

输入描述:

输入整数n,m。(1<=n,m<=1e6)

输出描述:

输出满足的对数。

示例1

输入

复制

6 7

输出

复制

6

说明

(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)

这到题就很nice了,感觉这个题很好;这里给出自己的思路;对于一来说每次 1 在7的倍数中,都会找到一个数,和其相加等于7的倍数比如:6,13,20;同理对于2 有:5,12,19;等等

所以我们首先要求出符合这种类型的树的个数也就是1,2,3,4,5,6,7的个数。所以a[1] = n / 7; a[2] = n / 7......

由于·存在不能整除的现象所以要低于小于n%7的数分别加1;然后求出他们的乘积就是答案;

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pi acos(-1)
#define e exp(1)
#define For(i, a, b) for(int (i) = (a); (i) <= (b); (i) ++)
#define Bor(i, a, b) for(int (i) = (b); (i) >= (a); (i) --)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define eps 1e-7
#define INF 0x3f3f3f3f
#define inf -2100000000
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxn = 100 + 10;
const double EPS = 1e-10;
const ll p = 1e7+9;
const ll mod = 1e9+7;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
inline int read(){
    int ret=0,f=0;char ch=getchar();
    while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
    while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
    return f?-ret:ret;
}
ll n,m;
int main(){
	ios::sync_with_stdio(false);
	cin  >> n >> m;
	ll sum = 0;
	for(int i = 1; i <= 6; i++){
		ll x = m / 7 + (((m % 7) >= i) ? 1 : 0);
        ll y = n / 7 + (((n % 7) >= (7 - i)) ? 1 : 0);
        sum += x * y;
	}
	sum += (n/7)*(m/7);
	cout << sum << endl;
	return 0;
}

好好加油

猜你喜欢

转载自blog.csdn.net/ab1605014317/article/details/84898720