Advertisement
Prohause

Strong Number

Oct 17th, 2018
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. $input = readline(); //Четем входа като String
  4. $n = str_split($input); //Правим масив от отделните цифри които сме получили на входа
  5. $sum = 0;
  6.  
  7. for ($i = 0; $i < count($n); $i++) { //обхождаме елементите в масива
  8. $curSum = 1;
  9. for ($j = 1; $j <= intval($n[$i]); $j++) { //извличаме факториел от всяко число в масива
  10. $curSum *= $j;
  11. }
  12. $sum += $curSum;
  13. }
  14.  
  15. if ($sum == intval($input)) {
  16. echo 'yes';
  17. } else {
  18. echo 'no';
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement