HDU6835 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=c1c2c3...cn¯(ciis 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≤t105) — the number of test cases.

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

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

这道题的题面翻译一下,就是在什么情况下,对于b进制数x以及任意b进制数y,y的各位数字的和能被x整除可以推出y能被x整除;y的各位数字的和不能被x整除可以推出y不能被x整除。

题解直接放了结论出来:b1(mod x)。但这个是怎么来的呢?不妨把y这个数写出来:y=c1bn1+c2bn2+...+cnb0,会发现其实这是一个自变量为b的多项式的值。由同余的性质:若ab(mod m),则f(a)f(b)(mod m),其中f(x)为整系数的一元多项式。因此如果令上式中a为1,b为题目中的b,那么可以由b1(mod x)推出y=c1bn1+c2bn2+...+cnb0 c1+c2+...+cn(mod x),而c1+c2+...+cn就是翻译过来的题面里的y的各位数字的和。

上面只是大体思路,具体证明见官方题解:

原命题等价于:对于任意的 b 进制正整数 y=c1c2cn¯,如果 c1+c2++cn0(modx),那么 y0(modx),否则 y0(modx)

上述命题成立当且仅当 b1(modx)

证明:

  • b1(modx) 时,有 yc1bn1+c2bn2++cnb0c1+c2++cn(modx),于是上述命题成立。
  • b1(modx) 时,假设上述命题成立,有:
    • xb,令 y=1b1+(x1)b0,则应有 yb+x10(modx),即 b1(modx),但此时 b1(modx),出现矛盾,于是上述命题不成立。
    • x>b,令 y=x=c1c2cn¯,显然 c1+c2++cn0(modx),于是 y0(modx),但 y0(modx),出现矛盾,于是上述命题不成立。

综上,上述命题成立当且仅当 b1(modx)

posted @   脂环  阅读(294)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩