Bismillahir Rahmanir Rahim
We think given number is 381.so distance between output's divisor is minimum 381.
We need to find a prime 382 or after that.if we get the prime then we again add 381 with that prime number.
then this or after this number prime is allowed.
so like the 1->(1+381)=382..untill get the prime...383->(383+381)=764..untill get the prime...769->(769*383)=294527
Output is 294527.
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll tst,num;
cin>>tst;
while(tst--)
{
cin>>num;
ll hello=num+1,point,flag;
for(ll i=hello;; i++)
{
flag=0;
for(ll j=2; j*j<=i; j++)
if(i%j==0)
{
flag=1;
break;
}
if(flag==0)
{
point=i;
break;
}
}
hello=point+num;
for(ll i=hello;; i++)
{
flag=0;
for(ll j=2; j*j<=i; j++)
if(i%j==0)
{
flag=1;
break;
}
if(flag==0)
{
cout<<point*i<<endl;
break;
}
}
}
return 0;
}
///Alhamdulillah
Problem Link: https://codeforces.com/problemset/problem/870/C
Comments
Post a Comment