1 solutions

  • 0
    @ 2025-11-27 11:58:27

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
     
    typedef long long LL;
    LL convert(int p, string s) {
        LL ans=0;
        reverse(s.begin(),s.end());
        for(int i=0; i<s.size(); i++) {
            if(s[i]>='A') ans+=(s[i]-'A'+10)*pow(p,i);
            else ans+=(s[i]-'0')*pow(p,i);
        }
        return ans;
    }
     
    int main() {
        int T;
        cin>>T;
        while(T--) {
            int p;
            string s;
            cin>>p>>s;
            cout<<convert(p,s)<<endl;
        }
        return 0;
    }
     
    /*
    in:
    2
    8 1362
    16 3F0
    out:
    754
    1008
    */
    
    • 1

    Information

    ID
    82
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By