Submission #14381346
Source Code Expand
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
// powのll番
ll pow(ll a,ll b) {
ll k = 1;
REP(_,b) k*=a;
return b;
}
void solve() {
ll A;
cin >> A;
FOR(i,10,10001) {
string str = to_string(i);
ll ans = 0;
REP(j,str.size()) {
int p = str.size()-1-j;
ans+=(pow(i,p)) * (str[j]-'0');
}
if (A==ans) {
cout << i << endl;
return;
}
}
cout << -1 << endl;
}
int main() {
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - N進数 |
| User | reud |
| Language | C++14 (GCC 5.4.1) |
| Score | 100 |
| Code Size | 1011 Byte |
| Status | AC |
| Exec Time | 4 ms |
| Memory | 384 KiB |
Judge Result
| Set Name | Sample | All | ||
|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||
| Status | AC |
|
| Set Name | Test Cases |
|---|---|
| Sample | |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 1 ms | 256 KiB |
| sample_02.txt | AC | 4 ms | 384 KiB |
| sample_03.txt | AC | 4 ms | 256 KiB |
| test_01.txt | AC | 4 ms | 256 KiB |
| test_02.txt | AC | 4 ms | 256 KiB |
| test_03.txt | AC | 4 ms | 256 KiB |
| test_04.txt | AC | 3 ms | 256 KiB |
| test_05.txt | AC | 3 ms | 256 KiB |
| test_06.txt | AC | 2 ms | 256 KiB |
| test_07.txt | AC | 4 ms | 256 KiB |
| test_08.txt | AC | 2 ms | 256 KiB |
| test_09.txt | AC | 1 ms | 256 KiB |
| test_10.txt | AC | 3 ms | 256 KiB |
| test_11.txt | AC | 4 ms | 256 KiB |
| test_12.txt | AC | 2 ms | 256 KiB |
| test_13.txt | AC | 1 ms | 256 KiB |
| test_14.txt | AC | 4 ms | 256 KiB |
| test_15.txt | AC | 1 ms | 256 KiB |
| test_16.txt | AC | 4 ms | 256 KiB |
| test_17.txt | AC | 4 ms | 256 KiB |
| test_18.txt | AC | 4 ms | 256 KiB |
| test_19.txt | AC | 4 ms | 256 KiB |
| test_20.txt | AC | 4 ms | 256 KiB |
| test_21.txt | AC | 4 ms | 256 KiB |
| test_22.txt | AC | 4 ms | 256 KiB |
| test_23.txt | AC | 4 ms | 256 KiB |