結果

問題 No.3403 Count 1210 Sequence
コンテスト
ユーザー tnakao0123
提出日時 2025-12-10 16:04:56
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
RE  
実行時間 -
コード長 1,910 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 580 ms
コンパイル使用メモリ 42,180 KB
実行使用メモリ 17,672 KB
最終ジャッジ日時 2025-12-10 16:05:11
合計ジャッジ時間 10,745 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 RE * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:73:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |   scanf("%d", &tn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:77:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   77 |     scanf("%d%d", &n, &a);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3403.cc:  No.3403 Count 1210 Sequence - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 2025;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator-() const { return MI(MOD - v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

using mi = MI<MOD>;

/* global variables */

mi dp[MAX_N + 1][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  dp[0][0] = 1;
  for (int i = 0; i < MAX_N; i++)
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] += dp[i][j];
      if (j > 0) dp[i + 1][j - 1] += dp[i][j];
    }
  
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n, a;
    scanf("%d%d", &n, &a);
    n--;

    mi sum = 0;
    for (int p = 1; p * p <= a; p++)
      if (a % p == 0) {
	int q = a / p;
	sum += dp[n][q];
	if (q != p) sum += dp[n][p];
      }

    printf("%d\n", (int)sum);
  }

  return 0;
}

0