Pagini recente » Cod sursa (job #1508871) | Cod sursa (job #2094817) | Cod sursa (job #3237749) | Cod sursa (job #2409003) | Cod sursa (job #2610597)
#include <iostream>
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
ifstream f("subsir1000.in");
ofstream g("subsir1000.out");
vector<int> diviz[nmax];
bool ciur[nmax];
int last[nmax],dp[nmax],sol=0;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
int main()
{
InParser f("subsir1000.in");
ofstream g("subsir1000.out");
int n;
f>>n;
for(int i=2;i<=2;i++)
{
if(ciur[i]==0)
{
for(int j=i;j<=n;j+=i)
{
diviz[j].push_back(i);
ciur[j]=1;
}
}
}
for(int i=3;i<=n;i+=2)
{
if(ciur[i]==0)
{
for(int j=i;j<=n;j+=i)
{
diviz[j].push_back(i);
ciur[j]=1;
}
}
}
for(int i=1;i<=n;i++)
{
int x;
f>>x;
dp[i]=1;
int l=diviz[x].size();
for(int j=0;j<l;j++)
{
dp[i]=max(dp[i],dp[last[diviz[x][j]]]+1);
last[diviz[x][j]]=i;
}
sol=max(sol,dp[i]);
}
g<<sol;
}