6 kyu
Playing with digits
3,732 of 144,389g964
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 | 355277 |
Total Skips | 74421 |
Total Code Submissions | 513090 |
Total Times Completed | 144389 |
Ruby Completions | 3732 |
Python Completions | 55418 |
C# Completions | 7975 |
Java Completions | 13898 |
JavaScript Completions | 43249 |
Haskell Completions | 1120 |
Clojure Completions | 284 |
CoffeeScript Completions | 89 |
C++ Completions | 6102 |
PHP Completions | 3105 |
Crystal Completions | 37 |
F# Completions | 109 |
Swift Completions | 864 |
C Completions | 3010 |
TypeScript Completions | 2480 |
Go Completions | 1811 |
Shell Completions | 167 |
OCaml Completions | 59 |
Julia Completions | 116 |
Scala Completions | 402 |
R Completions | 199 |
PowerShell Completions | 83 |
Kotlin Completions | 927 |
NASM Completions | 23 |
Nim Completions | 29 |
Rust Completions | 1400 |
Racket Completions | 32 |
Reason Completions | 8 |
Lua Completions | 153 |
CommonLisp Completions | 104 |
Pascal Completions | 22 |
Perl Completions | 26 |
Raku Completions | 7 |
Elm Completions | 12 |
D Completions | 9 |
COBOL Completions | 11 |
Prolog Completions | 13 |
Factor Completions | 10 |
Total Stars | 3589 |
% of votes with a positive feedback rating | 90% of 13635 |
Total "Very Satisfied" Votes | 11216 |
Total "Somewhat Satisfied" Votes | 2191 |
Total "Not Satisfied" Votes | 228 |