Cod sursa(job #567821)

Utilizator MKLOLDragos Ristache MKLOL Data 30 martie 2011 14:59:14
Problema Iepuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include<stdio.h>
#include <algorithm>
#define big biroiigras

using namespace std;

int N;
int best[101010];
int p;
int biroiigras[101010],x,maxim;
int prim[50100],k;
char ciur[101010];
void ciur1()
{
    for(int i=2;i<=N;++i)
    {
        if(!ciur[i])
        {
        prim[++k]=i;
        for(int j=i+i;j<=N;j+=i)
        {
            ciur[j]=1;
        }
        }
    }
}
int main()
{
freopen("subsir1000.in","r",stdin);
freopen("subsir1000.out","w",stdout);

    scanf("%d",&N);
    ciur1();
 // for(int i=1;i<=k;++i)
   // printf("%d ",prim[i]);
    for(int i=1;i<=N;++i)
    {scanf("%d",&p);
        big[i]=1;
        x=p;
        int j;
        for(int q=1;prim[q]<=x*x&&q<=k;++q)
        {
        j=prim[q];
            if(x%j==0)
            {
                big[i]=max(big[i],best[j]+1);
               while(x%j==0)
               x=x/j;
            }
        }
        if(x>1)
        {
            big[i]=max(big[i],best[x]+1);
        }
        x=p;
        for(int q=1;prim[q]<=x*x&&q<=k;++q)
        {j=prim[q];
            if(x%j==0)
            {
                best[j]=max(best[j],big[i]);
                 while(x%j==0)
                x=x/j;
            }
        }
        if(x>1)
        {
            best[x]=max(best[x],big[i]);
        }
        maxim=max(big[i],maxim);
      //  printf("%d %d\n",big[i],i);
    }
    printf("%d\n",maxim);
return 0;
}