-
Notifications
You must be signed in to change notification settings - Fork 5
/
CountDiv.php
61 lines (50 loc) · 1.22 KB
/
CountDiv.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* CountDiv
*
* Compute number of integers divisible by k in range [a..b].
*/
include '../../Tests.class.php';
function solution($A, $B, $K) {
$min = (int)($A/$K);
$max = (int)($B/$K);
$bonus = ($A % $K == 0) ? 1 : 0;
return $max - $min + $bonus;
}
$test = new Tests('CountDiv');
// example
// A = 6, B = 11, K = 2
$A = 6; $B = 11; $K = 2;
$result = 3;
$test->run(array($A, $B, $K), $result);
// simple
// A = 11, B = 345, K = 17
$A = 11; $B = 345; $K = 17;
$result = 20;
$test->run(array($A, $B, $K), $result);
// minimal
// A, B in {0,1}, K = 11
$A = rand(0,1); $B = rand(0,1); $K = 11;
$result = 1;
$test->run(array($A, $B, $K), $result);
// extreme_ifempty
// A = 10, B = 10, K in {5,7,20}
$A = 10; $B = 10; $K = 5;
$result = 1;
$test->run(array($A, $B, $K), $result);
$A = 10; $B = 10; $K = 7;
$result = 0;
$test->run(array($A, $B, $K), $result);
$A = 10; $B = 10; $K = 20;
$result = 0;
$test->run(array($A, $B, $K), $result);
//big_values
//A = 100, B=123M+, K=2
$A = 100; $B = 123000000; $K = 2;
$result = 61499951;
$test->run(array($A, $B, $K), $result);
//big_values2
//A = 101, B = 123M+, K = 10K
$A = 101; $B = 123000000; $K = 10000;
$result = 12300;
$test->run(array($A, $B, $K), $result);