QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860750#9981. Collatz Conjectureucup-team5234#WA 21ms3712kbC++204.7kb2025-01-18 14:48:542025-01-18 14:51:43

Judging History

你现在查看的是最新测评结果

  • [2025-01-18 14:51:43]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:3712kb
  • [2025-01-18 14:48:54]
  • 提交

answer

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")


#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using VVVV = VV<VV<T>>;
#define rep(i,n) for(ll i=0ll;(i)<(n);(i)++)
#define REP(i,a,n) for(ll i=(a);(i)<(n);(i)++)
#define rrep(i,n) for(ll i=(n)-1;(i)>=(0ll);(i)--)
#define RREP(i,a,n) for(ll i=(n)-1;(i)>=(a);(i)--)
const long long INF = (1LL << 60);
const long long mod99 = 998244353;
const long long mod107 = 1000000007;
const long long mod = mod99;
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
#define all(i,v) for(auto& (i) : (v))
#define UQ(v) sort(be(v)), (v).erase(unique(be(v)), (v).end())
#define UQ2(v,cmp) sort(be(v)), (v).erase(unique(be(v),cmp), (v).end())
#define UQ3(v,cmp) sort(be(v),cmp), (v).erase(unique(be(v)), (v).end())
#define UQ4(v,cmp,cmp2) sort(be(v), cmp), (v).erase(unique(be(v),cmp2), (v).end())
#define LB(x,v) (lower_bound(be(v),(x))-(v).begin())
#define LB2(x,v,cmp) (lower_bound(be(v),(x),(cmp))-(v).begin())
#define UB(x,v) (upper_bound(be(v),(x))-(v).begin())
#define UB2(x,v,cmp) (upper_bound(be(v),(x),(cmp))-(v).begin())
#define dout()  cout << fixed << setprecision(20)
#define randinit() srand((unsigned)time(NULL))

template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; }
template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; }


ll Rnd(ll L=0, ll R=mod99){return rand()%(R-L)+L;}



struct Combination{
    vector<long long> fac, inv, finv;
    long long MOD;
    Combination(long long N = 200100, long long p = 998244353) : fac(N, 1), inv(N, 1), finv(N, 1), MOD(p){
        for(long long i = 2; i < N; i++){
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long long com(long long n, long long k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
    }
    
    long long per(long long n, long long k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fac[n] * finv[n-k] % MOD;
    }
};

long long modpow(long long n, long long k, long long p = mod){
    long long a = n % p;
    long long ans = 1;
    while(k != 0) {
        if(k & 1) ans = ans * a % p;
        k /= 2;
        a = a * a % p;
    }
    
    return ans;  
}

// n^(-1) ≡ b (mod p) となる b を求める
long long modinv(long long n, long long p = mod) { 
//    if(n == 1) return 1;
//    return p - modinv(p % n) * (p / n) % p;
    return modpow(n, p - 2, p);
}

// n^k ≡ b (mod p) となる最小の k を求める
long long modlog(long long n, long long b, long long p = mod){
  
    long long sqrt_p = sqrt(p);
    unordered_map<long long , long long> n_pow;
    long long memo = 1;
    
    for(long long i = 0; i < sqrt_p; i ++){
        if(!n_pow.count(memo)) n_pow[memo] = i;
        memo = memo * n % p; 
    }
    
    memo = modinv(memo, p);
    long long ans = 0;
    while(!n_pow.count(b)){
        if(ans >= p) return -1;
        ans += sqrt_p;
        b = b * memo % p;
    }
  
    ans += n_pow[b];
    return ans % (p - 1);

}

// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long ext_gcd(long long a, long long b, long long &x, long long &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    long long d = ext_gcd(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void solve(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll nn = n;
    ll cnt = 0;
    ll xx,yy;
    ext_gcd(a, b, xx, yy);

    while(nn > b){
        ll x = xx, y = yy;
        y %= a;
        y *= (nn%a);
        y %= a;
        if(y > 0) y -= a;
        
        ll nx = nn - y*b;
        // cout << nn << " " << nx << endl;
        if(cnt){
            if(nn <= n and n <= nx and (n-nn)%b == 0){
                cout << "Yes\n";
                return;
            }
        }
        cnt++;
        nn = (nn - y*b) / a;
    }
    
    ll x = xx, y = yy;
    x %= b;
    x *= (nn % b);
    x %= b;
    if(x <= 0) x += b;
    // cout << nn << " " << x << " " << n << " " << x*a << endl;
    if(n > x*a){
        cout << "No\n";
        return;
    }
    cout << "Yes\n";




}





int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t=1;
    cin >> t;
    rep(i,t) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

7
2 1 1
2 1 2
2 1 3
2 1 100
314 159 265
314 159 2653
314 159 26535

output:

Yes
Yes
No
No
Yes
Yes
No

result:

ok 7 tokens

Test #2:

score: -100
Wrong Answer
time: 21ms
memory: 3712kb

input:

100000
123 457 1
123 457 2
123 457 3
123 457 4
123 457 5
123 457 6
123 457 7
123 457 8
123 457 9
123 457 10
123 457 11
123 457 12
123 457 13
123 457 14
123 457 15
123 457 16
123 457 17
123 457 18
123 457 19
123 457 20
123 457 21
123 457 22
123 457 23
123 457 24
123 457 25
123 457 26
123 457 27
123 4...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

wrong answer 505th words differ - expected: 'Yes', found: 'No'