Posts

Showing posts from February, 2025

6. Maths- part 2

Image
8.) Print all divisors/factors- Method-1 :  1 se n          tak ka loop chalake check divisibility of n with each i Method-2 : 1 se sqrt(n) tak ka loop chalado and print i and n/i as per divisibility  ----------------------------------------------------------------------------------------------------------------------------- 9.)  Prime number check- prime number- has exactly 2 divisors (1 and itself) Method-1 :  1 se n          tak dekhlo, ki it must have exactly 2 divisors... Method-2 :   1 se sqrt(n) tak dekhlo, ki it must have exactly 1 divisor... above methods ki cond true hai toh prime hoga...else not... ----------------------------------------------------------------------------------------------------------------------------- 10.) Prime factors of n- Method-1:      filter out primes out of all factors of n   Method-2:  1 se sqrt(N) tak save factors as per below code -------------...

23. Bit manipulation

Image
swap 2 numbers✅ get i-th bit (check set or not)✅ toggle i-th bit ✅ set or clear i-th bit✅ check number odd or not✅ remove last set bit⭐✅ count set bits⭐✅ set rightmost unset bit✅ check if power of 2✅ divide 2 numbers⭐✅ min flips in bits to convert A to B power set xor of all numbers from L to R✅ all no.s appear thrice except 1 number all no.s appear twice except 2 numbers - ------------------------------------------------------------------------------------------------------------- NOTE :- 1. decimal to binary  &   binary to decimal  conversion 2. since int is of  4byte i.e.,32 bits, so if  int x=17 (no. is just of 5 bits here) so rest 27 bits stores 0 3. One's complement - convert to binary and then 1 ki jagah 0 and vice versa     Two's complement - add 1 to the one's complement. 4.  (-ve) no.s in binary form- for decimals - an extra bit is appended at the start of binary no. to store info for sign , where 0 us for (+) and...