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 :
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
Similar Kata:
Stats:
Created | May 12, 2015 |
Published | May 12, 2015 |
Warriors Trained | 358205 |
Total Skips | 74808 |
Total Code Submissions | 516971 |
Total Times Completed | 145997 |
Ruby Completions | 3746 |
Python Completions | 56196 |
C# Completions | 8026 |
Java Completions | 14018 |
JavaScript Completions | 43682 |
Haskell Completions | 1126 |
Clojure Completions | 284 |
CoffeeScript Completions | 89 |
C++ Completions | 6168 |
PHP Completions | 3130 |
Crystal Completions | 37 |
F# Completions | 109 |
Swift Completions | 869 |
C Completions | 3039 |
TypeScript Completions | 2515 |
Go Completions | 1841 |
Shell Completions | 168 |
OCaml Completions | 60 |
Julia Completions | 116 |
Scala Completions | 403 |
R Completions | 201 |
PowerShell Completions | 84 |
Kotlin Completions | 939 |
NASM Completions | 23 |
Nim Completions | 29 |
Rust Completions | 1419 |
Racket Completions | 32 |
Reason Completions | 8 |
Lua Completions | 153 |
CommonLisp Completions | 111 |
Pascal Completions | 22 |
Perl Completions | 30 |
Raku Completions | 8 |
Elm Completions | 12 |
D Completions | 9 |
COBOL Completions | 11 |
Prolog Completions | 13 |
Factor Completions | 10 |
Total Stars | 3616 |
% of votes with a positive feedback rating | 90% of 13683 |
Total "Very Satisfied" Votes | 11256 |
Total "Somewhat Satisfied" Votes | 2199 |
Total "Not Satisfied" Votes | 228 |