結果

問題 No.435 占い(Extra)
ユーザー tossytossy
提出日時 2016-10-24 13:36:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 94,496 KB
実行使用メモリ 29,888 KB
最終ジャッジ日時 2024-04-17 02:49:40
合計ジャッジ時間 8,403 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
28,288 KB
testcase_01 AC 77 ms
22,892 KB
testcase_02 AC 71 ms
22,912 KB
testcase_03 AC 67 ms
22,912 KB
testcase_04 AC 71 ms
22,920 KB
testcase_05 AC 69 ms
22,700 KB
testcase_06 AC 69 ms
22,860 KB
testcase_07 AC 68 ms
22,852 KB
testcase_08 AC 70 ms
22,840 KB
testcase_09 AC 69 ms
22,912 KB
testcase_10 AC 103 ms
22,764 KB
testcase_11 AC 100 ms
22,836 KB
testcase_12 AC 449 ms
22,904 KB
testcase_13 AC 378 ms
22,856 KB
testcase_14 AC 341 ms
22,912 KB
testcase_15 AC 276 ms
22,768 KB
testcase_16 AC 140 ms
22,912 KB
testcase_17 AC 172 ms
22,768 KB
testcase_18 AC 464 ms
22,912 KB
testcase_19 AC 411 ms
22,904 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

vector<int> primes;

// x^n mod
long mod_pow(long x, long n, long mod){
  long res=1;
  while(n>0){
    if(n&1) res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

int main(){
  #define SZ 10000000
  vector<short> divs(SZ+1, 0); //divs[i] := iを割り切る素数のひとつ, 素数なら0
  for(int i=2; i<=SZ; i++) if(divs[i]==0){
    for(long j=(long)i*i; j<=SZ; j+=i) divs[j]=i;
  }

  int tc;
  scanf("%d\n", &tc);
  rep(loops, tc){
    int n,x,a,b,m;
    scanf("%d %d %d %d %d", &n ,&x, &a, &b, &m);

    bool isZero=true;
    vector<int> comb(9,0); //combinationの素因数分解
    int res = 0;

    rep(i,n){
      int r = x%10;
      if(r!=0) isZero=false;

      long cc=1;
      repl(j,2,9) cc *= mod_pow(j, comb[j], 9);
      res = (res + r * cc) % 9;

      int p = n-1-i;
      int q = i+1;
      while(divs[p]>0){
        comb[divs[p]%9]++;
        p /= divs[p];
      }
      comb[p%9]++;
      while(divs[q]>0){
        comb[divs[q]%9]--;
        q /= divs[q];
      }
      comb[q%9]--;

      x = ((x^a)%m + b)%m;
    }

    if(!isZero && res==0) res=9;
    printf("%d\n", res);
  }

  return 0;
}
0