6 kyu

Playing with digits

14,018 of 145,997g964

Description:

Some numbers have funny properties. For example:

  • 89 --> 8¹ + 9² = 89 * 1
  • 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2
  • 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51

Given two positive integers n and p, we want to find a positive integer k, if it exists, such that the sum of the digits of n raised to consecutive powers starting from p is equal to k * n.

In other words, writing the consecutive digits of n as a, b, c, d ..., is there an integer k such that :

(ap+bp+1+cp+2+dp+3+...)=nk(a^p + b^{p + 1} + c^{p + 2} + d^{p + 3} + ...) = n * k

If it is the case we will return k, if not return -1.

Note: n and p will always be strictly positive integers.

Examples:

n = 89; p = 1 ---> 1 since 8¹ + 9² = 89 = 89 * 1

n = 92; p = 1 ---> -1 since there is no k such that 9¹ + 2² equals 92 * k

n = 695; p = 2 ---> 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2

n = 46288; p = 3 ---> 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
Fundamentals
Mathematics

Stats:

CreatedMay 12, 2015
PublishedMay 12, 2015
Warriors Trained358205
Total Skips74808
Total Code Submissions516971
Total Times Completed145997
Ruby Completions3746
Python Completions56196
C# Completions8026
Java Completions14018
JavaScript Completions43682
Haskell Completions1126
Clojure Completions284
CoffeeScript Completions89
C++ Completions6168
PHP Completions3130
Crystal Completions37
F# Completions109
Swift Completions869
C Completions3039
TypeScript Completions2515
Go Completions1841
Shell Completions168
OCaml Completions60
Julia Completions116
Scala Completions403
R Completions201
PowerShell Completions84
Kotlin Completions939
NASM Completions23
Nim Completions29
Rust Completions1419
Racket Completions32
Reason Completions8
Lua Completions153
CommonLisp Completions111
Pascal Completions22
Perl Completions30
Raku Completions8
Elm Completions12
D Completions9
COBOL Completions11
Prolog Completions13
Factor Completions10
Total Stars3616
% of votes with a positive feedback rating90% of 13683
Total "Very Satisfied" Votes11256
Total "Somewhat Satisfied" Votes2199
Total "Not Satisfied" Votes228
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • naithar Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Voile Avatar
  • kdmatrosov Avatar
  • lbvf50mobile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • razetime Avatar
  • KayleighWasTaken Avatar
  • PetitLu117 Avatar
Ad