Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: RazielVonChronos
- * Date: 25-Nov-18
- * Time: 13:34 PM
- */
- $number = strval(readline());
- $n = intval(readline());
- // we are doing the match backwards so we need to take the index of the value and multiply it for each step.
- $index = 1;
- // put them in array so we can observe each record's behaviour
- $array = [];
- for ($i = (strlen($number) - 1); $i >= 0; $i--) {
- $array[] = sprintf('%.0f', ($number[$i] * $n) * $index);
- // $i's position defines how big the number(via $index) example 1, 10,100,100 and etc..
- $index = $index * 10;
- };
- //var_dump($array);
- // calling sprintf in order to print the big number normally.
- // using doubleval for more memory (big numbers sux)
- echo sprintf("%.0f", array_sum(array_map('doubleval', $array)));
- /*
- при вход:
- 923847238931983192462832102
- 4
- изхода се очаква да е
- 3695388955727932769851328408
- но ми връща
- 3695388955727932301651214336
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement