Editorial for Problem About Base


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

tr

Soruda belirtilen \(a\) dizisini şu şekilde bulabiliriz;

  • \(\mathbf{a_0} = \lfloor \frac{N}{K^0} \rfloor \mod K\)
  • \(\mathbf{a_1} = \lfloor \frac{N}{K^1} \rfloor \mod K\)
  • ...
  • \(\mathbf{a_{m-1}} = \lfloor \frac{N}{K^{m-1}} \rfloor \mod K\)
  • \(\mathbf{a_{m}} = \lfloor \frac{N}{K^{m}} \rfloor \mod K\)

Soruda bulduğumuz \(a\) dizisini tersi isteniyor.

en

We can find the series \(a\) specified in problem description as follows;

  • \(\mathbf{a_0} = \lfloor \frac{N}{K^0} \rfloor \mod K\)
  • \(\mathbf{a_1} = \lfloor \frac{N}{K^1} \rfloor \mod K\)
  • ...
  • \(\mathbf{a_{m-1}} = \lfloor \frac{N}{K^{m-1}} \rfloor \mod K\)
  • \(\mathbf{a_{m}} = \lfloor \frac{N}{K^{m}} \rfloor \mod K\)

The problem simply asks the reverse of the series \(a\).

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

long long n, k, t, arr[300005];

int main(){
    cin>>t;
    while(t--){
        cin>>n>>k;
        int i=0;
        while(n){
            arr[i]=n%k;
            n/=k;
            i++;
        }
        while(i--) cout<<arr[i];        
        cout<<endl;
    }
}