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*na∗n 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+(1−k)∗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=k,y=(10)k,sum=1=x+(1−k)
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+(1−k2)=x+(1−k)(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+(1−k3)=x+(1−k)(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*kX1∗1+X2∗k+...+Xt∗k
meanssum sums u m must beX + (1 − k) ∗ t X+(1-k)*tX+(1−k)∗t
Then we follow the meaning of the question:
a ∗ na*na∗n Kaseikkk- arysum = a ∗ n + (1 − k) ∗ t sum = a*n + (1-k)*tsum=a∗n+(1−k)∗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) a∗n+(1−k)∗t+by≡c ( 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;
}