You are on page 1of 5

//

,

If m1 and m2 are 2 maps and we want to copy m2
into m1 then,
m1.insert(m2.begin(),m2.end());


Output


floor(ln(number)/ln(base))
Range sum query, range minimum query
Segment Tree Binary Index Tree (BIT)

If n is a number then,

n=p a1 + p a2 + + pak
1

Where

pi

is a prime number.
a
( 1+1) ( a 2+1 ) .( ak +1)

Number of divisor=

Sum of divisor=
(1+ p1 + p ++ pa3 )( 1+ p 2+ p 22+ + p a2 ) .(1+ pk + p2k ++ p ak )
2
1

p1a +11 p a2 +11


pak +11
.

p 11
p 21
pk 1
1

, ( )
Sort an array keeping track of index
Sort digit wise

Divisor
1
2

5
6
7

Divisibility condition
Examples
No special condition. Any integer
2 is divisible by 1.
is divisible by 1.
The last digit is even (0, 2, 4, 6, or
1,294: 4 is even.
8).[1][2]
405 4 + 0 + 5 = 9 and 636 6 + 3 + 6 = 15
which both are clearly divisible by 3.
Sum the digits. If the result is
16,499,205,854,376
divisible by 3, then the original
1+6+4+9+9+2+0+5+8+5+4+3+7+6 sums to 69 6
number is divisible by 3.[1][3][4]
+ 9 = 15 1 + 5 = 6, which is clearly divisible by
3.
Subtract the quantity of the digits Using the example above: 16,499,205,854,376 has
2, 5, and 8 in the number from the four of the digits 1, 4 and 7 and four of the digits 2,
quantity of the digits 1, 4, and 7 in 5 and 8; Since 4 4 = 0 is a multiple of 3, the
the number.
number 16,499,205,854,376 is divisible by 3.
[1][2]
Examine the last two digits.
40832: 32 is divisible by 4.
If the tens digit is even, the ones
digit must be 0, 4, or 8.
40832: 3 is odd, and the last digit is 2.
If the tens digit is odd, the ones
digit must be 2 or 6.
Twice the tens digit, plus the ones
40832: 2 3 + 2 = 8, which is divisible by 4.
digit.
The last digit is 0 or 5.[1][2]
495: the last digit is 5.
1,458: 1 + 4 + 5 + 8 = 18, so it is divisible by 3 and
[5]
It is divisible by 2 and by 3.
the last digit is even, hence the number is divisible
by 6.
Form the alternating sum of blocks
1,369,851: 851 369 + 1 = 483 = 7 69
of three from right to left.[4][6]
Subtract 2 times the last digit from
the rest. (Works because 21 is
483: 48 (3 2) = 42 = 7 6.
divisible by 7.)
Or, add 5 times the last digit to the
rest. (Works because 49 is divisible 483: 48 + (3 5) = 63 = 7 9.
by 7.)
Or, add 3 times the first digit to the
next. (This works because 10a + b
483: 43 + 8 = 20 remainder 6, 63 + 3 = 21.
7a = 3a + b last number has
the same remainder)
Multiply each digit (from right to 483595: (4 (-2)) + (8 (-3)) + (3 (-1)) + (5 2)
left) by the digit in the
+ (9 3) + (5 1) = 7.
corresponding position in this
pattern (from left to right): 1, 3, 2,
-1, -3, -2 (repeating for digits

9
10

11

12

13

14

beyond the hundred-thousands


place). Then sum the results.
If the hundreds digit is even,
examine the number formed by the 624: 24.
last two digits.
If the hundreds digit is odd,
examine the number obtained by 352: 52 + 4 = 56.
the last two digits plus 4.
Add the last digit to twice the rest. 56: (5 2) + 6 = 16.
Examine the last three digits.[1][2] 34152: Examine divisibility of just 152: 19 8
Add four times the hundreds digit
to twice the tens digit to the ones 34152: 4 1 + 5 2 + 2 = 16
digit.
Sum the digits. If the result is
divisible by 9, then the original
2,880: 2 + 8 + 8 + 0 = 18: 1 + 8 = 9.
[1][3][4]
number is divisible by 9.
The last digit is 0.[2]
130: the last digit is 0.
Form the alternating sum of the
918,082: 9 1 + 8 0 + 8 2 = 22.
digits.[1][4]
Add the digits in blocks of two
627: 6 + 27 = 33.
from right to left.[1]
Subtract the last digit from the rest. 627: 62 7 = 55.
Add the last digit to the hundredth
place (add 10 times the last digit to 627: 62 + 70 = 132.
the rest).
If the number of digits is even, add
918,082: the number of digits is even (6) 1808 +
the first and subtract the last digit
9 2 = 1815: 81 + 1 5 = 77 = 7 11
from the rest.
If the number of digits is odd,
14,179: the number of digits is odd (5) 417 1
subtract the first and last digit from
9 = 407 = 37 11
the rest.
It is divisible by 3 and by 4.[5]
324: it is divisible by 3 and by 4.
Subtract the last digit from twice
324: 32 2 4 = 60.
the rest.
Form the alternating sum of blocks
2,911,272: 2 + 911 272 = 637
of three from right to left.[6]
Add 4 times the last digit to the
637: 63 + 7 4 = 91, 9 + 1 4 = 13.
rest.
Subtract 9 times the last digit from
637: 63 - 63 = 0.
the rest.
It is divisible by 2 and by 7.[5]
224: it is divisible by 2 and by 7.
Add the last two digits to twice the
364: 3 2 + 64 = 70.
rest. The answer must be divisible
1764: 17 2 + 64 = 98.
by 14.

15

16

17
18
19
20

It is divisible by 3 and by 5.[5]


390: it is divisible by 3 and by 5.
If the thousands digit is even,
examine the number formed by the 254,176: 176.
last three digits.
If the thousands digit is odd,
examine the number formed by the 3,408: 408 + 8 = 416.
last three digits plus 8.
176: 1 4 + 76 = 80.
Add the last two digits to four
times the rest.
1168: 11 4 + 68 = 112.
Examine the last four digits.[1][2]
Subtract 5 times the last digit from
the rest.
It is divisible by 2 and by 9.[5]
Add twice the last digit to the rest.
It is divisible by 10, and the tens
digit is even.
If the number formed by the last
two digits is divisible by 20.

157,648: 7,648 = 478 16.


221: 22 1 5 = 17.
342: it is divisible by 2 and by 9.
437: 43 + 7 2 = 57.
360: is divisible by 10, and 6 is even.
480: 80 is divisible by 20.

You might also like