为什么不能用复合运算式
查看原帖
为什么不能用复合运算式
875806
liupan2010楼主2023/2/19 09:48

10 分代码:

#include<bits/stdc++.h>
#define int long long
const int mod=998244353;
using namespace std;
int fpow(int a,int b)
{
    long long t=1;
    while(b)
    {
        if(b&1)
            t*=a%mod;
        b>>=1;
        a*=a%mod;
    }
    return t;
}
signed main()
{
	int k,n;
	cin>>n>>k;
	cout<<fpow(fpow(2,k)-1,n);
	return 0;
}

AC 代码:

#include<bits/stdc++.h>
#define int long long
const int mod=998244353;
using namespace std;
int fpow(int a,int b)
{
    int t=1;
    while(b)
    {
        if(b&1)
            t=t*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return t;
}
signed main()
{
	int k,n;
	cin>>n>>k;
	cout<<fpow(fpow(2,k)-1,n);
	return 0;
}

可以发现,将t*=a%mod改成t=t*a%mod就能过,求原因。

2023/2/19 09:48
加载中...