結果
| 問題 | No.3478 XOR-Folding Primes |
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2026-03-20 21:38:15 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 339 ms / 4,000 ms |
| コード長 | 2,391 bytes |
| 記録 | |
| コンパイル時間 | 3,329 ms |
| コンパイル使用メモリ | 282,016 KB |
| 実行使用メモリ | 10,308 KB |
| 最終ジャッジ日時 | 2026-03-20 21:38:26 |
| 合計ジャッジ時間 | 9,910 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
/**
author: shobonvip
created: 2026.03.20 21:21:14
**/
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
const int mx = 10000050;
vector<bool> p(mx + 1, true);
p[0] = false;
p[1] = false;
for (int i=2; i<=mx; i++) {
if (!p[i]) continue;
for (int j=2*i; j<=mx; j+=i) {
p[j] = false;
}
}
vector<int> tb;
vector<int> pl;
for (int i=2; i<=mx; i++) {
if (p[i]) pl.emplace_back(i);
}
for (int i=5; i<=mx-2; i++) {
if (p[i] && p[i+2] && i%4==1) {
tb.emplace_back(i+2);
}
}
int t;
cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
if (n == 1) {
int L = int(upper_bound(all(pl), m) - pl.begin());
cout << L << '\n';
continue;
}
int L = int(upper_bound(all(tb), m) - tb.begin());
vector mat(2, vector<mint>(2));
mat[0][0] = 0;
mat[1][0] = 2 * L;
mat[1][1] = 1;
mat[0][1] = 1;
vector<mint> ans(2);
ans[0] = 1;
ans[1] = 2 * L;
n--;
while(n > 0) {
if (n & 1) {
vector<mint> nans(2);
rep(i,0,2) {
rep(j,0,2) {
nans[i] += mat[i][j] * ans[j];
}
}
swap(ans, nans);
}
vector nmat(2, vector<mint>(2));
rep(i,0,2) {
rep(j,0,2) {
rep(k,0,2) {
nmat[i][j] += mat[i][k] * mat[k][j];
}
}
}
swap(nmat, mat);
n >>= 1;
}
cout << (ans[0] + ans[1]).val() << '\n';
}
}
shobonvip