結果

問題 No.473 和と積の和
ユーザー rickythetarickytheta
提出日時 2016-12-23 01:05:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 400 ms / 3,000 ms
コード長 2,617 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 157,372 KB
実行使用メモリ 33,264 KB
最終ジャッジ日時 2023-08-22 08:24:49
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 120 ms
20,204 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 32 ms
8,384 KB
testcase_26 AC 57 ms
12,764 KB
testcase_27 AC 20 ms
6,972 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 8 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 75 ms
12,304 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 232 ms
26,448 KB
testcase_39 AC 400 ms
33,264 KB
testcase_40 AC 196 ms
20,076 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 9 ms
5,404 KB
testcase_44 AC 68 ms
15,164 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

struct myhash{
  size_t operator()(const vi &v) const {
    hash<int> hsh;
    size_t ret=0;
    for(int x:v){
      ret ^= hsh(x);
      ret = ret ^ (ret<<13);
      ret = ret ^ (ret>>17);
      ret = ret ^ (ret<<5);
    }
    return ret;
  }
};

int main(){
  int n;
  int x;
  cin>>n>>x;
  x++;
  int num = 0;
  {
    int t=x;
    for(int p=2;p*p<=t;p++){
      while(t%p==0)t/=p,num++;
    }
    if(t!=1)num++;
    if(n>num){
      puts("0");
      return 0;
    }else if(n==num){
      puts("1");
      return 0;
    }
  }
  typedef unordered_set<vi,myhash> ss;
  // factorize x with n numbers
  ss S;
  S.insert(vi(n,1));
  for(int p=2;p*p<=x;p++){
    while(x%p==0){
      x/=p;
      num--;
      ss nxt;
      for(const vi &X : S){
        REP(i,n){
          if(i>0 && X[i]==X[i-1])continue;
          vi add(n,0);
          int nw = X[i]*p;
          int it = 0;
          REP(j,n){
            while(it==i)it++;
            if(it<n && X[it]<nw)add[j]=X[it++];
            else{
              add[j]=nw;
              nw = (1<<30) + 252;
            }
          }
          if(num<n && add[num]==1)continue;
          nxt.insert(add);
        }
      }
      swap(S,nxt);
    }
  }
  if(x!=1){
    num--;
    ss nxt;
    for(const vi &X : S){
      REP(i,n){
        if(i>0 && X[i]==X[i-1])continue;
        vi add(n,0);
        int nw = X[i]*x;
        int it = 0;
        REP(j,n){
          while(it==i)it++;
          if(it<n && X[it]<nw)add[j]=X[it++];
          else{
            add[j]=nw;
            nw = (1<<30) + 252;
          }
        }
        if(num<n && add[num]==1)continue;
        nxt.insert(add);
      }
    }
    swap(S,nxt);
  }
  int ans = S.size();
  // for(const vi &X : S){
  //   if(X[0]!=1)ans++;
  // }
  printf("%d\n",ans);
  return 0;
}
0