Spoj DIV2 - Divisors 2 Solution

 


Problem Link: https://www.spoj.com/problems/DIV2/

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int const n = 1000000;
int divisors[n];
bool vis[n ];
vector<int>prime;
void sol()
{
    for(int i = 1; i <=n ; ++i)
    {
        for(int j = i; j <= n; j += i)
        {
            divisors[j]++;
        }
    }
    memset(vis,true,sizeof vis);
    for(int i = 1; i <=n ; ++i)
    {
        for(int j = i; j <= n; j += i)
        {
            if(divisors[j]<=3||j%i!=0||divisors[j]%divisors[i]!=0)
                vis[j]=false;
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(vis[i])
            prime.push_back(i);
    }
}
int main()
{
   sol();
   for(int i=107;i<=prime.size();i+=108)
    cout<<prime[i]<<endl;

}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.