QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567562#9309. GraphcomeintocalmWA 54ms85500kbC++201.6kb2024-09-16 12:47:062024-09-16 12:47:08

Judging History

你现在查看的是最新测评结果

  • [2024-09-16 12:47:08]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:85500kb
  • [2024-09-16 12:47:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int mod = 998244353;
LL Fpow(LL b, LL k) {
  LL res = 1;
  b %= mod;
  while(k > 0) {
    if(k & 1) res = res * b % mod;
    k /= 2;
    b = b * b % mod; 
  }
  return res;
}
const int M2 = 1e7;
const int N = 1e7+4;

int prm[N], pcnt = 0, vis1[N], preS[N];
void euler_0() {
  for(int i = 2; i <= M2; i++) {
    if(!vis1[i]) {
      prm[++pcnt] = i;
    }
    preS[i] = pcnt;
    for(int j = 1; j <= pcnt && prm[j] * i <= M2; j++) {
      vis1[prm[j] * i] = prm[j];
      if(i % prm[j] == 0) break;
    }
  }
}

int getsqrt(LL n) {
  LL t = sqrt(n);
  while((t + 1) * (t + 1) <= n) t++;
  return t;
}

int getexp(LL n, int p) {
  int t = log(n) / log(p);
  while(pow(p, t + 1) <= n) t++;
  return t;
}

void solve(LL n) {
  int bound = getsqrt(n);
  LL s_atb = 1, leafed = 0;
  for(int i = 1; i <= pcnt && prm[i] <= bound; i++) {
    int up_bd = getexp(n, prm[i]);
    LL base = prm[i];
    
    if(up_bd >= 3 && pow(prm[i], up_bd) * 2 > n) 
      leafed++;
    
    for(int j = 1; j <= up_bd; j++, base *= prm[i]) {
      LL sF = n / base - n / (base * prm[i]);
      LL pF = n / 2 / base - n / 2 / (base * prm[i]);
      s_atb = s_atb * Fpow(up_bd - j + 1, (sF - pF) % (mod - 1)); 
    }
  }

  LL alpha = preS[n] - preS[n / 2] + 1;
  LL bans = (n - alpha) % mod * Fpow(2, leafed % (mod - 1)) % mod;

  //cout << alpha << "  ???" << n << "\n";

  LL ans = Fpow(n, (alpha - 1) % (mod - 1)) * bans % mod * s_atb % mod;

  cout << ans << "\n";
}

int main() {
  euler_0(); 
  LL n;
  cin >> n;
  if(n > 10000000) while(1);
  solve(n);
}

詳細信息

Test #1:

score: 100
Accepted
time: 37ms
memory: 85500kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 84720kb

input:

2

output:

0

result:

wrong answer expected '1', found '0'