Posts

Showing posts with the label prime

ALL Number product resulted number divisor count

Problem:  https://acm.timus.ru/problem.aspx?space=1&num=1049 # include <bits/stdc++.h> using namespace std ; typedef long long ll; # define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0); int status[ 100000000 / 32 ]; bool Check ( int N, int pos) { return ( bool )(N & ( 1 <<pos));} int Set ( int N, int pos) { return N=N | ( 1 <<pos);} long long int arr[ 10000000 ]; long long int l= 0 ,a,b= 100000 ,n; void sieve () { long long int i,j,sqrtN; sqrtN = int ( sqrt ( b ) ); for ( i= 3 ; i<=sqrtN; i+= 2 ) { if ( Check(status[i/ 32 ],i% 32 )== 0 ) { for (j=i*i; j<=b; j+= 2 *i) { status[j/ 32 ]=Set(status[j/ 32 ],j% 32 ); } } } arr[ 0 ]= 2 ; l= 1 ; for (i= 3 ;i<=b;i+= 2 ) { if (Check(status[i/ 32 ],i% 32 )== 0 ) { arr[l]=i; l++; } } } long lo...

Bool check prime or not

Not time efficient. /* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; bool checkPrime(int p) {     if(p==1)     {         return false;     }     else if(p==2)     {         return true;     }     else     {         for(int i=2; i*i<=p; i++)         {             if(p%i==0)             {                 return false;             }         }         return true;     } } int main() {     int a,b,c,flag;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c;     ...