Modulus (conclusion of base conversion, extended Euclidean properties)

Modulus
meaning:
Given four positive integers a, b, c, ka,b,c,ka,b,c,k , answer whether there is a positive integernnn such thata ∗ na*nan atkkThe sum of the values ​​of each bit in the k- ary representation modulobbb isccc

First give a conclusion:
a decimal number xxx化成kkk baseyyy, 那yyThesumof each digit of y sum sums u m must bex + (1 − k) ∗ t x+(1-k)*tx+(1k)t

Simple proof:

x < k x < k x<k, 那y = xy = xand=x
supposex >= kx >= kx>=k
1. x = k , y = ( 10 ) k , s u m = 1 = x + ( 1 − k ) x = k,y = (10)_k,sum=1=x+(1-k) x=ky=(10)ksum=1=x+(1k)
2. x = k 2 , y = ( 100 ) k , s u m = 1 = x + ( 1 − k 2 ) = x + ( 1 − k ) ( 1 + k ) x=k^2,y=(100)_k,sum=1=x+(1-k^2)=x+(1-k)(1+k) x=k2,and=(100)k,sum=1=x+(1k2)=x+(1k)(1+k)
3. x = k 3 , y = ( 1000 ) k , s u m = 1 = x + ( 1 − k 3 ) = x + ( 1 − k ) ( k 2 + k + 1 ) x=k^3,y=(1000)_k,sum=1=x+(1-k^3)=x+(1-k)(k^2+k+1) x=k3,and=(1000)k,sum=1=x+(1k3)=x+(1k)(k2+k+1 )
……
For any numberXXX can be written asX 1 ∗ 1 + X 2 ∗ k +... + X t ∗ k X_1*1+X_2*k+...+X_t*kX11+X2k+...+Xtk
meanssum sums u m must beX + (1 − k) ∗ t X+(1-k)*tX+(1k)t

Then we follow the meaning of the question:
a ∗ na*nan Kaseikkk- arysum = a ∗ n + (1 − k) ∗ t sum = a*n + (1-k)*tsum=an+(1k)t ;
To satisfysum% b = c sum\% b = csum%b=c也就是 a ∗ n + ( 1 − k ) ∗ t + b y ≡ c ( m o d b ) a*n+(1-k)*t+by\equiv c(mod b) an+(1k)t+byc ( m o d b )
According to the extended Euclidean property,ccc must begcd (n, t, b) gcd(n,t,b)gcd(n,t,b ) is a multiple of the solution.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
    
    
    return y == 0 ? x : gcd(y, x%y);
}
int main() {
    
    
    int t;
    cin >> t;
    while(t--) {
    
    
        ll a, b, c, k;
        cin >> a >> b >> c >> k;
        if(c % gcd(gcd(a, b), (1-k)) != 0) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45363113/article/details/108873521