Math, asked by taha9781, 1 year ago

Given a positive integer n written as abcd... (a, b, c, d... Being digits) and a positive integer p we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. In other words: in php

Answers

Answered by fruitwargi
3
hey mate here is your answer..


function digPow(n, p) { var m = n; var i, sum = 0; var j = 0; var l = n.toString().length; var digits = []; while (n >= 10) { digits.unshift(n % 10); n = Math.floor(n / 10); } digits.unshift(n); for (i = p; i < l + p; i++) { sum += Math.pow(digits[j], i); j++; } if (sum % m == 0) { return sum / m; } else return -1; } alert(digPow(89, 1))

hope it helps you dear

pb65Jatt: nice sis
Similar questions