結果

問題 No.390 最長の数列
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-07-09 00:33:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,519 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 91,552 KB
実行使用メモリ 11,528 KB
最終ジャッジ日時 2024-04-21 08:58:38
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,392 KB
testcase_01 AC 7 ms
11,392 KB
testcase_02 AC 8 ms
11,268 KB
testcase_03 AC 8 ms
11,392 KB
testcase_04 AC 8 ms
11,392 KB
testcase_05 AC 67 ms
11,432 KB
testcase_06 AC 72 ms
11,264 KB
testcase_07 AC 9 ms
11,392 KB
testcase_08 AC 8 ms
11,392 KB
testcase_09 WA -
testcase_10 AC 76 ms
11,392 KB
testcase_11 WA -
testcase_12 AC 80 ms
11,392 KB
testcase_13 AC 64 ms
11,240 KB
testcase_14 AC 73 ms
11,364 KB
testcase_15 AC 9 ms
11,460 KB
testcase_16 AC 8 ms
11,392 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[1000005];

int isPrime(int n) {
  int i;

  if (n < 2) {
    return 0;
  }
  else if (n == 2) {
    return 1;
  }

  if (n % 2 == 0) {
    return 0;
  }

  for (i = 3; i * i <= n; i += 2) {
    if (n % i == 0) {
      return 0;
    }
  }

  return 1;
}

int main() {
  ll n;
  cin >> n;
  clr(d, 0);
  rep(i, 0, n) {
    ll a;
    cin >> a;
    d[a] = 1;
  }
  vector<int> v;
  rep(i,2,1005){
    if(isPrime(i)==0)continue;
    rep(j,1,20){
      if(pow(i,j)>1000000)break;
      v.pb(pow(i,j));
    }
  }
  rep(i,0,1000005){
    if(d[i]==0)continue;
    rep(j,0,v.sz){
      if(i*v[j]>1000000)continue;
      if(d[i*v[j]]!=0){
        d[i*v[j]] = max(d[i*v[j]],d[i]+1);
      }
    }
  }
  ll mx = 0;
  rep(i,0,1000005){
    mx = max(mx,d[i]);
  }
  cout << mx << endl;
  return 0;
}

0