B3828 题解
题目传送门
在本题中,我们既可以枚举
首先需要判断正整数
然后开始判断
接下来就是读入
不过考虑到答案可能很大,于是开个 __int128 是个不错的主意。因为此代码的时间复杂度正确,也不会有太多常数。
最后特别地,若求积变量仍为初始值,则说明在
于是得代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int __int128
template<typename T>inline void rd(T &x){x=0;char c=getchar();bool f=0;while(!isdigit(c)){if(c=='-'){f=1;}c=getchar();}while(isdigit(c)){x=(x<<3)+(x<<1)+(c^'0');c=getchar();}if(f){x=~(x-1);}}
template<typename T,typename...Args>inline void rd(T &x,Args&...args){rd(x);rd(args...);}
inline void wt(int x){if(x<0){putchar('-'),x=-x;}if(x>9){wt(x/10);}putchar(x%10+'0');}
#define pc(x) putchar(x)
#define wtl(x) wt(x),pc('\n')
#define kg pc(' ')
#define hh pc('\n')
const int p=998244353;
inline bool chk(int x)
{
if(x<=1)
{
return 0;
}
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
return 0;
}
}
return 1;
}
int a[1000001];
signed main()
{
int cnt=0;
for(int i=1;i*i<=1e12;i++)
{
int x=i*i;
int ans=0;
while(x)
{
int t=x%10;
ans+=t;
x/=10;
}
if(chk(ans))
{
cnt++;
a[cnt]=i*i;
}
}
int l,r;
rd(l,r);
int ans=1;
for(int i=1;i<=cnt;i++)
{
if(a[i]>=l&&a[i]<=r)
{
ans=(ans*a[i])%p;
}
}
wtl(ans==1?0:ans);
return 0;
}