import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long x = scanner.nextLong(); long k = scanner.nextLong(); System.out.println(radix(x, k)); } private static String radix(long x, long k) { StringBuilder sb = new StringBuilder(); if (x == 0) { sb.append(0); } while (x != 0) { sb.append(x % k); x /= k; } return sb.reverse().toString(); } }
import java.io.*; public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] str=br.readLine().split(" "); long n=Long.parseLong(str[0]); int m=Integer.parseInt(str[1]); System.out.println(Long.toString(n,m)); } }
#include <iostream> #define ULLI unsigned long long int using namespace std; string conv(ULLI x, int base) { if (!x) return ""; return conv(x / base, base) + to_string(x % base); } int main(const int argc, const char* argv[]) { ios::sync_with_stdio(false); cin.tie(0); ULLI x; int base; fscanf(stdin, "%lld %d", &x, &base); if (!x) { cout << "0"; return 0; } cout << conv(x, base); return 0; }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] params = br.readLine().trim().split(" "); long x = Long.parseLong(params[0]); int k = Integer.parseInt(params[1]); StringBuilder sb = new StringBuilder(); while(x > 0){ sb.append(x % k); x /= k; } System.out.println(sb.length() > 0? sb.reverse(): x); } }
#include <iostream> #include <string> using namespace std; int main(){ long long x; int k; string str; cin >> x >> k; if(x == 0){ cout << 0 << endl; return 0; } while(x){ if(x % k == 0){ str = to_string(0) + str; } else{ str = to_string(x % k) + str; } x /= k; } cout << str << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string changeNum(long long num,long long x){ if(num==0) return "0"; stack<int> st; while(num>0){ st.push(num%x); num/=x; } string str; while(!st.empty()){ str+=st.top()+'0'; st.pop(); } return str; } int main(){ long long n,x; cin>>n>>x; cout<<changeNum(n,x); return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <list> #include <math.h> #include <set> #include <cstdio> #include <queue> #include <sstream> #include <stack> //#define DBL_MAX 1.7976931348623158e+308 using namespace std; typedef long long ll; #define BIG 1000000000 //习惯性带上上面 void f(ll n, int x) { stack<int> sta; while (n != 0) { sta.push(n % x); n = n / x; } while (!sta.empty()) { cout << sta.top(); sta.pop(); } cout << endl; } int main() { ll n; int x; cin >> n >> x; if (n == 0) { cout << 0 << endl; } else{ f(n, x); } return 0; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(), radix = sc.nextLong(); StringBuffer sb = new StringBuffer(); if (n == 0) { sb.append(0); } while (n > 0) { sb.append( n % radix); n /= radix; } System.out.println(sb.reverse().toString()); return; } }
public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long num = sc.nextLong(); int k = sc.nextInt(); System.out.println(transfer(num, k)); } } public static String transfer(long num, int k) { if (num == 0) return "0"; StringBuilder sb = new StringBuilder(); while (num != 0) { sb.append(num % k); num /= k; } return sb.reverse().toString(); } }
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); long num = sc.nextLong(); long j = sc.nextInt(); long z, y; ArrayList<Long> res = new ArrayList<>(); if(num == 0){ System.out.println(0); }else{ while(num != 0){ z = num/j; y = num%j; res.add(y); num = z; } Collections.reverse(res); } for (long n: res) { System.out.print(n); } } }
#include<iostream> #include<stack> using namespace std; void f(long long x,int t){ if(x/t==0){ cout<<x; return ; } ; f(x/t,t); cout<<x%t; } void f1(long long x,int t){ stack<int> s1; while(x){ s1.push(x%t); x/=t; } if(s1.empty()){ cout<<0; return ; } while(!s1.empty()){ cout<<s1.top(); s1.pop(); } } int main(){ long long x;int t; cin>>x>>t; f(x,t);//递归 //f1(x,t);//栈 return 0; }
#include<iostream> #include<vector> using namespace std; int main() { long long int n; int m; vector<int> s; while (cin >> n >> m) { int a = 0, b = 0, c = 0; if(n==0){ cout<<0; } while (n != 0) { a = n % m; s.push_back(a); n = (n - a) / m; } for (int i = s.size() - 1; i >= 0; i--) { cout << s[i]; } cout << endl; } return 0; }
x,k=map(int,input().split()) s='' if x==0: print(0) else: while x: s=str(x%k)+s x=x//k print(s)