結果

問題 No.473 和と積の和
ユーザー rickythetarickytheta
提出日時 2016-12-23 01:18:06
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 367 ms / 3,000 ms
コード長 1,725 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 56,176 KB
実行使用メモリ 33,076 KB
最終ジャッジ日時 2024-12-16 04:06:22
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |   scanf("%d%d",&n,&x);
      |   ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <unordered_set>

using namespace std;

typedef vector<int> vi;

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)

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 n,x;

typedef unordered_set<vi,myhash> ss;
ss po,nxt;
int num;
void step(int p){
  num--;
  nxt.clear();
  for(const vi &X : po){
    vi add(n,0);
    int nw = X[0]*p;
    int it = 1;
    REP(j,n){
      if(it<n && X[it]<nw)add[j]=X[it++];
      else{
        add[j]=nw;
        nw = (1<<30) + 252;
      }
    }
    nxt.insert(add);
    if(num>=n || X[num]!=1){
      FOR(i,1,n){
        if(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;
          }
        }
        nxt.insert(add);
      }
    }
  }
  swap(po,nxt);
}

int main(){
  scanf("%d%d",&n,&x);
  x++;
  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;
    }
  }
  // factorize x with n numbers
  po.insert(vi(n,1));
  for(int p=2;p*p<=x;p++){
    while(x%p==0){
      x/=p;
      step(p);
    }
  }
  if(x!=1)step(x);
  int ans = po.size();
  printf("%d\n",ans);
  return 0;
}
0