Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $num1 = readline();
- $num2 = intval(readline());
- if ($num1 === '0' || $num2 === 0) {
- echo '0';
- return;
- }
- $digits = [];
- for ($i = 0; $i < strlen($num1); $i++) {
- $digits[] = intval($num1[$i]);
- }
- $remainder = 0;
- $result = $digits;
- for ($j = 0; $j < $num2 - 1; $j++) {
- for ($k = count($digits) - 1; $k >= 0; $k--) {
- $sum = $result[$k] + $digits[$k] + $remainder;
- if ($sum > 9 && $k !== 0) {
- $result[$k] = $sum % 10;
- $remainder = 1;
- } else {
- $result[$k] = $sum;
- $remainder = 0;
- }
- }
- }
- echo implode('', $result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement