結果

問題 No.435 占い(Extra)
ユーザー tnakao0123tnakao0123
提出日時 2016-10-30 18:40:42
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,818 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 84,664 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-17 02:51:24
合計ジャッジ時間 7,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 37 ms
5,376 KB
testcase_11 AC 30 ms
5,376 KB
testcase_12 RE -
testcase_13 AC 350 ms
5,376 KB
testcase_14 AC 278 ms
5,376 KB
testcase_15 AC 201 ms
5,376 KB
testcase_16 AC 79 ms
5,376 KB
testcase_17 AC 102 ms
5,376 KB
testcase_18 RE -
testcase_19 AC 351 ms
5,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |   scanf("%d", &tn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:80:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |     scanf("%d%lld%d%d%d", &ni, &xi, &ai, &bi, &mi);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 435.cc: No.435 占い(Extra) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MOD = 9;

/* typedef */

typedef long long ll;

/* global variables */

int dvs[MAX_N + 1];

/* subroutines */

void gen_dvs(int maxp) {
  for (int p = 2; p * p <= maxp; p++)
    if (! dvs[p])
      for (int q = p * p; q <= maxp; q += p) dvs[q] = p;
}

ll powmod(ll a, int b) {
  ll pm = 1;
  while (b > 0) {
    if (b & 1) pm = pm * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return pm;
}

ll pfs2ll(int pfs[]) {
  if (pfs[0] > 0) return 0;
  ll r = 1;
  for (int a = 1; a < MOD; a++)
    r = r * powmod((ll)a, pfs[a]) % MOD;
  return r;
}

/* main */

// nCr = n(n-1)..(n-r+1)/r!
// nC(r+1) = n(n-1)..(n-r)/(r+1)!
// -> nC(r+1) = nCr*(n-r)/(r+1)

int main() {
  gen_dvs(MAX_N);
  
  int tn;
  scanf("%d", &tn);
  while (tn--) {
    int ni, ai, bi, mi;
    ll xi;
    scanf("%d%lld%d%d%d", &ni, &xi, &ai, &bi, &mi);

    int n = ni - 1;
    
    ll ans = 0;
    bool nz = false;
    int pfs[MOD] = {0};

    for (int i = 0; i <= n; i++) {
      int d = xi % 10;
      if (d > 0) nz = true;
      ans = (ans + pfs2ll(pfs) * d) % MOD;

      if (i < n) {
	int j = n - i;
	while (dvs[j]) pfs[dvs[j] % MOD]++, j /= dvs[j];
	pfs[j % MOD]++;

	int k = i + 1;
	while (dvs[k]) pfs[dvs[k] % MOD]--, k /= dvs[k];
	pfs[k % MOD]--;
      }

      xi = ((xi ^ ai) + bi) % mi;
    }

    if (nz && ans == 0) ans = MOD;
    printf("%lld\n", ans);
  }
  return 0;
}
0