Cod sursa(job #2675085)
Utilizator | Data | 21 noiembrie 2020 09:58:43 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 1.79 kb |
#include <iostream>
using namespace std;
long long c,i,n,a,cnt,q,t,aux,ok;
int main()
{
cin>>c>>n;
if(c==1)
{
if(n==1 || n==2)
{
cout<<"1";
return 0;
}
cnt=2;
t=1;
aux=cnt;
i=3;
while(i<=n)
{
if(cnt!=0)
{
a=t;
cnt--;
t++;
i++;
}
else
{
q=1;
while(q<=t-1)
{
a=q;
q=q+2;
i++;
}
cnt=aux+1;
aux=cnt;
t=1;
}
}
cout<<a;
}
else
{
if(n==1)
{
cout<<"1";
return 0;
}
cnt=2;
t=1;
aux=cnt;
i=3;
ok=0;
while(1)
{
if(cnt!=0)
{
a=t;
cnt--;
t++;
if(a==n)
{
cout<<i;
break;
}
i++;
}
else
{
q=1;
while(q<=t-1)
{
a=q;
q=q+2;
if(a==n)
{
cout<<i;
ok=1;
break;
}
i++;
}
if(ok==1)
break;
cnt=aux+1;
aux=cnt;
t=1;
}
}
}
return 0;
}