QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197613 | #6890. Guess | haze | WA | 46ms | 19016kb | C++23 | 1.9kb | 2023-10-02 17:41:46 | 2023-10-02 17:41:46 |
Judging History
answer
#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
const int itinf = 2e9;
const ll llinf = 4e18;
const int mod = 998244353;
const int N = 500009;
ll qpow(LL a, ll b, LL md){
LL ans = 1;
while(b){
if(b & 1)ans *= a, ans %= md;
a *= a, a %= md, b >>= 1;
}
return ans;
}
bool check(ll n) {
if (n < 3 || n % 2 == 0) return n == 2;
ll u = n - 1, t = 0;
while (u % 2 == 0) u /= 2, ++t;
for (int i = 0; i < 8; ++i) {
ll a = rand() % (n - 2) + 2, v = qpow(a, u, n);
if (v == 1) continue;
ll s;
for (s = 0; s < t; ++s) {
if (v == n - 1) break;
v = (long long)v * v % n;
}
if (s == t) return 0;
}
return 1;
}
int isp[1000999] = {1,1};
vector<int>pri;
set<ll>avl;
int main(){
int pmax = 1000000;
for(int i = 2; i <= pmax; ++ i){
if(! isp[i])pri.push_back(i);
for(int p : pri){
if(1ll * i * p > pmax)break;
isp[i * p] = 1;
}
}
for(ll p : pri){
for(LL t0 = p; t0 <= llinf; t0 *= p)avl.insert(t0);
}
int T = read();
while(T --){
ll n = read();
if(check(n)){
printf("%lld ", n % mod);
continue;
}
ll k = sqrt(n);
if((k + 1) * (k + 1) == n) ++ k;
if(k * k == n){
if(check(k))printf("%lld ", n % mod);
else printf("%lld ", 1);
continue;
}
if(avl.find(n) == avl.end())printf("1 ");
else printf("%lld ",n % mod);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 46ms
memory: 19016kb
input:
2000 19491001 1 998244353 26952597531 861547697451441000 996491788296388609 981763655235363000 1024000007168 996491787298144256 973929762490885200 891042123129958800 878912224686896400 804111184288011600 766710664088569200 930867627131442000 996491787298144256 812033461965726000 964953451315854000 8...
output:
19491001 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer 1st lines differ - expected: '19491001 1 0 1 1 0 1 1 1 1 1 1...66159 899999557 1 716046715 1 1', found: '19491001 1 0 1 1 0 1 1 1 1 1 1... 557176661 1 318259321 1 1 1 1 '