2020杭电多校 第六场 Divisibility(结论)

Problem Description
You are given two 10-based integers b and x, and you are required to determine the following proposition is true or false:

For arbitrary b-based positive integer y=c1c2⋯cn⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ (ci is the i-th dight from left of y), define f(y)=∑i=1nci, if f(f(⋯f(y)⋯))∞ can be divided by x, then y can be divided by x, otherwise y can’t be divided by x.

Input
The first line contains a 10-based integer t (1≤t≤105) — the number of test cases.

For each test case, there is a single line containing two 10-based integers b and x (2≤b,x≤1018).

Output
For each test case, if the proposition is true, print “T”, otherwise print “F” (without quotes).

Sample Input
1
10 3

Sample Output
T

Source

思路:
只有 b m o d    x = 1 b\mod x=1 才行
题解为:
在这里插入图片描述
这种与数位、进制有关,且要求模数为0的题目,一般都是要转换为同余方程考虑。

很久很久以前在BZOJ也写过一道类似的题 BZOJ4724. [POI2017]Podzielno (神题,数论+二分)

那道题的结论是 B进制数要被B-1整除,要求B进制数位和为B-1倍数。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;
const int maxn = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int main() {
    int T;scanf("%d",&T);
    while(T--) {
        ll n,b;scanf("%lld%lld",&n,&b);
        if((n - 1) % b == 0) {
            printf("T\n");
        } else {
            printf("F\n");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/tomjobs/article/details/107853216
今日推荐