Program samaj nhi aaya

large number prime check

  1. bitset kya hota ??, yaha toh array ki tarah kaam rkr rha h toh array kyu nhi liya ??
  2. bool isprime() function m if and else dono m return kr rhe h toh for loop kyu lagaya vaha tak toh program pohochna hi nhi chahiye usse pehle hi return kr jana chahiye ??
  3. aur vector prime ki need hi kya h ??

which part you does not understand??

han m uper edit krke vahi likha rha tha
ab likh diya uper

  1. A bitset is an array of bool but each Boolean value is not stored separately instead bitset optimizes the space such that each bool takes 1 bit space only, so space taken by bitset bs is less than that of bool bs[N] and vector bs(N).


if No is less than n we have to check from bitset and return accordingly
otherwise we make a loop and check if is divisible return false
and after come out of loop we return true

  1. vector of prime contains only prime nos where as bitset array contains whether ith no is prime or not

@asaurabh_26
bhai se 10^7 yeh no max hoga yeh kese decide kraa ??
10^7 ya 10^8 bhi toh ho skta tha
long long lag ke aur bhi toh bada skte the na

@anujsharmabadboy,
Maximum would be given in problem, you can choose accordingly.

worst case m maximum kya hoga ??

aur yeh primes[i]* (long long)primes[i] bhi samaj nhi aaya

@anujsharmabadboy,

  • Maximum would not be more than 1e7.
  • The explicit conversion is done, so that there’s no overflow.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.