思路:
真的是搞人,一个bug能找俩小时
把题意转化求这个等式,其中aa表示的是x中数值为p的质因子的个数,bb表示的是y中数值为p的质因子个数

因为求他们的gcd就相当于求其质因数分解后的每个质因子的最小数目的乘积。然后再算每个质因子对答案的贡献。
详细看大佬的博客叭,太详细了 Orz
这里需要用到:
a ^ b % p == a ^ (b%(p-1)) % p
AC代码
#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
ll a,b,c,d,x,y,sum = 1;
ll quick_pow(ll a,ll b,ll p)
{
ll ans = 1;
while(b)
{
if(b&1)
ans = a*ans%p;
b>>=1;
a = a*a%p;
}
return ans;
}
void solve(ll num)
{
ll numa = 0,numb = 0,ans = 0;
while(x % num == 0) numa++,x/=num;
while(y % num == 0) numb++,y/=num;
if(numa == 0 || numb == 0) return ;
for(ll i = a;i <= b;i++)
{
ll j = numa*i/numb;
if(j < c) ans = ans + (d-c+1)*numa%(mod-1)*i%(mod-1);
else if(j >= d) ans = ans + (c+d)*(d-c+1)/2%(mod-1)*numb%(mod-1);
else ans = (ans + (d-j)*numa%(mod-1)*i%(mod-1) + (j+c)*(j-c+1)/2%(mod-1)*numb%(mod-1))%(mod-1);
ans %= (mod-1);
}
sum = sum*quick_pow(num,ans,mod)%mod;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> a >> b >> c >> d >> x >> y;
for(ll i = 2;i * i <= x;i++)
if(x % i == 0)
solve(i);
if(x > 1) solve(x);
cout << sum << endl;
}
本文深入探讨了一个复杂的数学问题,通过质因数分解和快速幂算法优化,解决了一个涉及大数运算的编程挑战。文章详细解释了如何利用快速幂的性质a^b%p==a^(b%(p-1))%p来简化计算过程,同时提供了AC代码示例,展示了如何遍历可能的质因数并计算其对最终答案的贡献。
358

被折叠的 条评论
为什么被折叠?



