【2020杭电多校】第六场 Divisibility 打表

传送门

题意

给出两个十进制整数 (b) , (x) ,有推理如下:

对于任意一个 (b) 进制整数 (y=c_1c_2c_3...c_n),定义(f(y))=(sum_{i=1}^{n}c_i),如果(f(f(...f(y)...))) 可以被 (x)整除,那么 (y) 也可以被 (x) 整除 。

如果当前推理正确,输出 T ,否则输出 F 。

思路

签到题,当时没有想出来,队友 A 了。

image-20200807164131043

另外当时竟忘记了打表!脑子瓦特了

打表 (b) 在 30 内的情况,满足的 (b , x) 对如下:

3 2 
4 3 
5 2 
5 4 
6 5 
7 2 
7 3 
7 6 
8 7 
9 2 
9 4 
9 8 
10 3
10 9
11 2
11 5
11 10
12 11
13 2
13 3
13 4
13 6
13 12
14 13
15 2
15 7
15 14
16 3
16 5
16 15
17 2
17 4
17 8
17 16
18 17
19 2
19 3
19 6
19 9
19 18
20 19
21 2
21 4
21 5
21 10
21 20
22 3
22 7
22 21
23 2
23 11
23 22
24 23
25 2
25 3
25 4
25 6
25 8
25 12
25 24
26 5
26 25
27 2
27 13
27 26
28 3
28 9
28 27
29 2
29 4
29 7
29 14
29 28
30 29

打表代码

#include <bits/stdc++.h>
#define fuck system("pause")
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int arr[N];

int check(int b, int x, int num)
{
    int rel = num;
    while (num >= b) {
        int tmp = num;
        int cnt = 0;
        while (tmp) {
            arr[++cnt] = tmp % b;
            tmp /= b;
        }
        num = 0;
        for (int i = 1; i <= cnt; i++) {
            num += arr[i];
        }
    }
    if ((num % x) ^ (rel % x))
        return 0;
    return 1;
}

int main()
{
    for (int i = 3; i <= 30; i++) {
        for (int j = 2; j < i; j++) {
            int flag = 1;
            for (int k = 1; k <= 100; k++) {
                if (!check(i, j, k)) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                printf("%d %d
", i, j);
            }
        }
    }
    return 0;
}

AC代码

#include <bits/stdc++.h>
#define fuck system("pause")
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        ll b, x;
        scanf("%lld%lld", &b, &x);
        if((b-1)%x==0){
            printf("T
");
        }
        else
            printf("F
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/valk3/p/13453847.html