Problem:
Dudeney Number
A Dudeney number is a positive integer for which the sum of its decimal digits is equal to the cube root of the number. For example, $512$ is a Dudeney number because it is the cube of $8$, which is the sum of its decimal digits ($5 + 1 + 2$).
In this problem, we think of a type similar to Dudeney numbers and try to enumerate them.
Given a non-negative integer $a$, an integer $n$ greater than or equal to 2 and an upper limit $m$, make a program to enumerate all $x$’s such that the sum of its decimal digits $y$ satisfies the relation $x = (y + a)^n$, and $x \leq m$.
Input
The input is given in the following format.
$a$ $n$ $m$
The input line provides three integers: $a$ ($0 \leq a \leq 50$), $n$ ($2 \leq n \leq 10$) and the upper limit $m$ ($1000 \leq m \leq 10^8$).
Output
Output the number of integers that meet the above criteria.
Sample Input 1
16 2 1000
Sample Output 1
2
Two:  $400 = (4 + 0 + 0 + 16)^2$ and $841 = (8 + 4 + 1 + 16)^2$
Sample Input 2
0 3 5000
Sample Output 2
3
Three: $1=1^3$, $512 = (5 + 1 + 2)^3$ and $4913 = (4 + 9 + 1 + 3)^3$.
Sample Input 3
2 3 100000
Sample Output 3
0
There is no such number $x$ in the range below $100,000$ such that its sum of decimal digits $y$ satisfies the relation $(y+2)^3 = x$.

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using dl=double;
using vi=vector<int>;
using vpi=vector<pair<int,int>>;

int main(){
  int a,n,m; cin>>a>>n>>m;
  int count=0;
  for(int i=1; i<m; i++){
    int d=i;
    int s=0;
    while(d>0){
      s=s+d%10;
      d=d/10;
    }
    int c=1;
    for(int j=0; j<n; j++){
      c=c*(s+a);
    }
    if(i==c){
      count++;
    }
  }
  cout<<count<<endl;
}
accuracy: 1
time_ms: 950
memory_kb: 3404
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return true;} return false;}
constexpr int INF = 1e9;

int dsum(ll x) {
    int sum = 0;
    while (x != 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {
    ll a, n, m; cin >> a >> n >> m;
    int cnt = 0;
    for (int x = 1; x <= m; x++) {
        int y = dsum(x);
        int X = 1;
        for (int i = 0; i < n; i++) {
            X *= (y+a);
        }
        if (x == X) cnt++;
    }
    cout << cnt << endl;
}
accuracy: 1
time_ms: 890
memory_kb: 3400
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int a, n, m;
    cin >> a >> n >> m;
    
    int ans = 0;
    rep(x, 1, m + 1) {
        ll sum = a;
        int tmp = x;
        while (tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        
        ll mul = 1;
        rep(itr, 0, n) {
            mul *= sum;
            if (mul > x) break;
        }
        if (mul == x) ++ans;
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 990
memory_kb: 3452
final_rank: 16

code_snippet: #include <stdio.h>
typedef long long ll;

ll a, n, m;
int check(int x) {
  ll y = 0;
  ll v = x;
  while (v) { y += v % 10; v /= 10; }
  ll w = 1;
  for (int i = 0; i < n; i++) w *= (y + a);
  return x == w;
}

int main() {
  scanf("%lld %lld %lld", &a, &n, &m);
  int cnt = 0;
  for (int x = 1; x <= m; x++) cnt += check(x);
  printf("%d\n", cnt);
  return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 2960
final_rank: 2

code_snippet: #include <stdio.h>
typedef long long ll;

ll a, n, m;
int check(int x){
  ll y = 0;
  ll v = x;
  while (v) {
    y += v % 10;
    v /= 10;
  }
  ll w = 1;
  for ( int i = 0; i < n; i++){
    w *= (y + a);
  }
  return x == w;
}

int main() {
  scanf("%lld %lld %lld", &a, &n, &m);
  int cnt = 0;
  for (int x = 1; x <= m; x++) {
    if (check(x)) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}
accuracy: 1
time_ms: 880
memory_kb: 2960
final_rank: 1

code_snippet: #include <iostream>
using namespace std;

long long a, n, m;
bool check(int x){
  long long y = 0;
  long long v = x;
  while(v){
    y += v%10;
    v /= 10;
  }
  long long w = 1;
  for ( int i = 0; i < n; i++){
    w *= (y + a);
  }
  return x == w;
}

int main() {
  cin >> a >> n >> m;
  int cnt = 0;
  for ( int x = 1; x <= m; x++ ){
    if ( check(x) ) cnt++;
  }
  cout << cnt << endl;
}
accuracy: 1
time_ms: 880
memory_kb: 3420
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(x,y) __gcd(x,y) //最大公約数
#define lcm(x,y) x/(__gcd(x,y))*y //最小公倍数
#define alpha_size 26 //アルファベットの文字数

int main() {
  int a, n, m;
  cin >> a >> n >> m;
  int count = 0;
  for (int x = 1; x <= m; x++) {
    unsigned ll ans = 1;
    int y = 0;
    int tmp = x;
    while (tmp > 0) {
      y += tmp % 10;
      tmp /= 10;
    }
    for (int i = 0; i < n; i++) {
      ans *= (y + a);
    }
    if (x == ans) {
      count++;
    }
  }
  cout << count << "\n";
  return(0);
}
accuracy: 1
time_ms: 960
memory_kb: 3368
final_rank: 11

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

int main() {
    int a, n, m, ans = 0;
    cin >> a >> n >> m;
    long long x;
    string dig;
    for (int i = m; i > 0; i--) {
        dig = to_string(i);
        x = 0;
        for (int j = 0; j < dig.length(); j++) {
            x += dig[j] - '0';
        }
        if ((long long)pow(x, n) == i) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.13333333333333333
time_ms: 10
memory_kb: 3840
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
int rec(int n){
  if(n==0){
    return 0;
  }
  else{
    return n%10+rec(n/10);
  }
}
int roc(int a,int n){
  if(n==0){
    return 1;
  }
  else{
    return a*roc(a,n-1);
  }
}
int main(){
  int a,n,m;
  cin >> a >> n >> m;
  int answer=0;
  for(int x=1;x<=m;x++){
    if(x==roc(rec(x)+a,n)) answer++;
  }
  cout << answer << endl;
}
accuracy: 1
time_ms: 960
memory_kb: 3440
final_rank: 15

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,n) for(long long i=a;i<n;i++)
#define repp(i,a,n) for(long long i=a;i>=n;i--)
#define so(z) sort(z.begin(),z.end())
#define sor(z) sort(z.begin(),z.end(),greater<string>())
#define re(z) reverse(z.begin(),z.end())
#define su(a) substr(a)
#define sub(a,b) substr(a,b)
#define yess cout<<"YES"<<nn
#define noo cout<<"NO"<<nn
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define yesr cout<<"Yes"<<"\n";return(0)
#define nor cout<<"No"<<"\n";return(0)
#define fi first
#define se second
#define fr() front()
#define mp make_pair
#define pb push_back
#define nn "\n"
#define ll unsigned long long
#define mod 1000000007
#define IM INT_MAX
#define LM LONG_LONG_MAX
#define gcd(x,y) __gcd(x,y) //最大公約数
#define lcm(x,y) x/(__gcd(x,y))*y //最小公倍数
#define prev(a) prev_permutation(a.begin(),a.end()) //辞書前
#define next(a) next_permutation(a.begin(),a.end()) //辞書後
#define get(s) getline(cin,s) //　空白の空いたstringの入力
#define fixed(a) fixed<<setprecision(a) //小数点何桁か指定
#define ro(a) round(a) //四捨五入
#define ce(a) ceil(a) //切り上げ
#define up(a,v) upper_bound(a.begin(),a.end(),v)
#define lo(a,v) lower_bound(a.begin(),a.end(),v)
#define bi(a,v) binary_bound(a.begin(),a.end(),v)
using namespace std;
ll a,n,m,ans=0;
ll check(ll i,ll s,ll t){
    ll b=0,c=1,z=i;
    while(z!=0){
        b+=z%10;
        z/=10;
    }
    while(t!=0){
        c*=(b+s);
        t--;
    }
    return(c);
}
int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    cin>>a>>n>>m;
    rep(i,1,m+1){
        if(check(i,a,n)==i) ans++;
    }
    cout<<ans<<nn;
    return(0);
}
accuracy: 1
time_ms: 980
memory_kb: 3172
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
bool chmin(ll & p,ll q){
    if(p>q){
        p=q;
        return 1;
    }
    else return 0;
}
int main() {
    
    ll a,n,m;
    cin>>a>>n>>m;
    ll an=0;
    for(ll x=1;x<=m;x++){
        ll p=x;
        ll s=a;
        rep(k,9){
            s+=p%10;
            p/=10;
        }
        ll d=1;
        rep(k,n){
            if(d>x){
                d=-1;
                break;
            }
            d*=s;
        }

        an+=(x==d);
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 890
memory_kb: 3436
final_rank: 12

code_snippet: #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#include <functional>
#include <cassert>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n) - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
bool chmax(T &a, const U &b){ return a < b ? (a = b, 1) : 0; }
template<class T, class U>
bool chmin(T &a, const U &b){ return a > b ? (a = b, 1) : 0; }
int m;
ll Pow(ll a, ll n){
  ll res = 1;
  rep(i, n){
    res *= a;
    if(res > m) return -1;
  }
  return res;
}
int digit_sum(int x){
  int res = 0;
  while(x){
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main(){
  int a,n;
  cin >> a >> n >> m;
  int ans = 0;
  for(int i = 1; i <= m; i++){
    if(i == Pow(a + digit_sum(i), n)) ans++;
  }
  cout << ans << "\n";
}
accuracy: 1
time_ms: 880
memory_kb: 3416
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long int;
int main() {
  ll a,n,m;
  cin >> a >> n >> m;
  ll cou=0;
  for(ll x=1; x<=m; x++) {
    ll y=0;
    ll xc=x;
    ll xc2=x;
    while(1) {
      if(xc<10) {
	y+=xc;
	break;
      }
      y+=xc%10;
      xc/=10;
    }
    //cout << 1 << endl;
    ll z=1;
    for(ll i=0; i<n; i++) {
      z*=(y+a);
    }
    //cout << xc2 << endl;
    if(z==xc2) cou++;
  }
  cout << cou << endl;
}
accuracy: 1
time_ms: 840
memory_kb: 3416
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int sumd(int x) {
    int res = 0;
    while (x != 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

int main() {
    ll a, n, m;
    cin >> a >> n >> m;

    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        int y = sumd(i);

        int b = 1;
        for(int j = 0; j < n; ++j) {
            b *= (y + a);
            if (b > i) break;
        }

        if (b == i)
            ans++;
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 900
memory_kb: 3412
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int sumd(int x) {
    int res = 0;
    while (x != 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

int main() {
    ll a, n, m;
    cin >> a >> n >> m;

    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        int y = sumd(i);

        int b = 1;
        rep(j, n) {
            b *= (y + a);
            if (b > i) break;
        }

        if (b == i)
            ans++;
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 900
memory_kb: 3412
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int a,n,m;
    cin >> a >> n >> m;
    int ans = 0;
    int x,y;
    for(int i=1;i<=m;i++){
        x = i;
        if(x < 10){
            y = x;
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100){
            y = x / 10 + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000){
            y = x / 100 + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000){
            y = x / 1000 + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100000){
            y = x / 10000 + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000000){
            y = x / 100000 + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000000){
            y = x / 1000000 + (x / 100000 - x / 1000000 * 10) + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x == 10000000){
            y = 1;
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.6666666666666666
time_ms: 840
memory_kb: 3356
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int a,n,m;
    cin >> a >> n >> m;
    int ans = 0;
    int x,y;
    for(int i=1;i<=m;i++){
        x = i;
        if(x < 10){
            y = x;
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100){
            y = x / 10 + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000){
            y = x / 100 + (x / 10 - x / 100 * 10) + (x - x / 100 * 100 - (x / 10 - x / 100 * 10) * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000){
            y = x / 1000 + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100000){
            y = x / 10000 + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000000){
            y = x / 100000 + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000000){
            y = x / 1000000 + (x / 100000 - x / 1000000 * 10) + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x == 10000000){
            y = 1;
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.6666666666666666
time_ms: 840
memory_kb: 3396
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int a,n,m;
    cin >> a >> n >> m;
    int ans = 0;
    int x,y;
    for(int i=1;i<=m;i++){
        x = i;
        if(x < 10){
            y = x;
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100){
            y = x / 10 + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000){
            y = x / 100 + (x / 10 - x / 100 * 10) + (x - x / 100 * 100 - (x / 10 - x / 100 * 10) * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000){
            y = x / 1000 + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 100000){
            y = x / 10000 + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 1000000){
            y = x / 100000 + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }else if(x < 10000000){
            y = x / 1000000 + (x / 100000 - x / 1000000 * 10) + (x / 10000 - x / 100000 * 10) + (x / 1000 - x / 10000 * 10) + (x / 100 - x / 1000 * 10) + (x / 10 - x / 100 * 10) + (x - x / 10 * 10);
            if(x==pow(y+a,n)){
                ans = ans + 1;
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.6666666666666666
time_ms: 830
memory_kb: 3348
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int inf=mod*mod;
const double eps=1e-9;
signed main(){
	int a,n,m;
	cin>>a>>n>>m;
	int ans=0;
	for(int i=1;i<=m;i++){
		int ii=i,sum=0,prod=1;
		while(ii){
			sum+=ii%10;
			ii/=10;
		}
		for(int i=0;i<n;i++)
			prod*=(sum+a);
		if(prod==i)
			ans++;
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 970
memory_kb: 3396
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (int __i = 0; __i < (n); __i++)
#define rep2(i, n) for (int i = 0; i < (n); i++)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#include <experimental/iterator>
#define outcon(os, c, sep) \
    copy(cbegin(c), cend(c), experimental::make_ostream_joiner(os, sep))
#ifdef LOCAL
#define dbg(x) cerr << "line" << __LINE__ << ": " << #x << " = " << (x) << "\n"
#else
#define dbg(x) true
#endif
template <class T>
bool ch(const T &(*f)(const T &, const T &), T &a, const T &b) {
    return a != f(a, b) and (a = b, true);
}
#define chmax(a, b) ch(max, a, b)
#define chmin(a, b) ch(min, a, b)
struct IOSetup {
    IOSetup() noexcept {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} IOSetup;
#define mut auto &&
#define imm const auto &

int digit_sum(int n) {
    if (n < 10) return n;
    return n % 10 + digit_sum(n / 10);
}

int main() {
    int a, n, m;
    cin >> a >> n >> m;
    int ans = 0;
    auto check = [&n, &a](int x) -> bool {
        int y = digit_sum(x);
        y += a;
        rep(n) {
            if (x % y == 0)
                x /= y;
            else
                return false;
        }
        return x == 1;
    };
    for (int x = 1; x <= m; x++) {
        if (check(x)) ans++;
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 780
memory_kb: 3456
final_rank: 4