贝壳找房算数(简单)

题目链接

贝壳找房算数(简单)

题解

简单题,因为数据规模不大,直接暴力运算即可

代码

#include <iostream>
#include <math.h>
using namespace std;
#define max___(a,b) (a>b?a:b)
#define min___(a,b) (a<b?a:b)
#define LL long long
#define maxll 1000000000000000
LL n, m,t,j,k;
LL a[10005];
long long gcd(long long x, long long y) {

    if (x>y)return gcd(y, x);
    if (x == 0)return y;
    return gcd(y%x, x);

}
int tq(int n) {
    int ans = 1;
    while (n) {
        ans = ans * (n % 10);
        n = n / 10;
    }
    return ans;
}
int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        a[i] = tq(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i] * a[j] <= 0) {
                continue;
            }
            if (gcd(a[i], a[j]) <= k) {
                ans++;
                ans %= 998244353;
            }
        }
    }
    std::cout << ans;
}

标签: implementation, math

添加新评论