NaCly_Fish @ 2019-02-04 23:30:03
题解给出的式子有误,应该是这样的:
设:
那么:
还有编译好像有毒?本机没问题,结果提交CE?
code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<bitset>
#define N 1000003
#define inf 0x3f3f3f3f
#define int long long
#define p 998244353
using namespace std;
int pw[N],inv[N],fac[N];
int n,ans,ng,t,ad,rs;
inline void read(int &x);
void print(int x);
void init();
inline int C(int x,int y);
inline int pow(int a,int t);
signed main(){
read(n);
init();
for(int i=0;i<n;++i){
ng = (i&1)?1:-1;
t = pow(1-pw[i],n)-pow(-pw[i],n);
ad = (ng*t%p*C(n,i)%p+p)%p;
ans = (ans+ad)%p;
}
ans = ans*3%p;
for(int i=1;i<=n;++i)
rs = (rs+pow(3,(n*(n-i)+i)%(p-1))*((i&1)?1:-1)%p*C(n,i)%p);
rs = (rs%p+p)%p;
rs = (rs<<1)%p;
ans = (ans+rs)%p;
print(ans);
return 0;
}
inline int C(int x,int y){
if(x<y) return 0;
return fac[x]*inv[y]%p*inv[x-y]%p;
}
void init(){
pw[0] = inv[1] = fac[0] = fac[1] = 1;
pw[1] = 3;
for(int i=2;i<=n;++i){
fac[i] = fac[i-1]*i%p;
inv[i] = (p-p/i)*inv[p%i]%p;
pw[i] = pw[i-1]*3%p;
}
inv[0] = 1;
for(int i=2;i<=n;++i)
inv[i] = inv[i]*inv[i-1]%p;
}
inline void read(int &x){
x = 0;
char c = getchar();
while(c<'0'||c>'9') c = getchar();
while(c>='0'&&c<='9'){
x = (x<<3)+(x<<1)+(c^48);
c = getchar();
}
}
void print(int x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
inline int pow(int a,int t){
int res = 1;
while(t){
if(t&1) res = res*a%p;
a = a*a%p;
t >>= 1;
}
return res;
}
by NaCly_Fish @ 2019-02-04 23:35:35
有谁知道怎么玄学CE了吗。。
这是提交记录:
QAQ
by _•́へ•́╬_ @ 2019-02-04 23:39:11
@NaCly_Fish rs = (rs+pow(3,(n*(n-i)+i)%(p-1))*((i&1)?1:-1)%p*C(n,i)%p);
有double
%long long
,当然不对
by Sai0511 @ 2019-02-04 23:43:55
@NaCly_Fish C++本身自己有一个pow函数,返回的值时double.
您本机编译的时候可能把那个pow函数重载了,但编译器没有。
试试换个函数名
by chenyanming @ 2019-02-04 23:44:03
@NaCly_Fish pow返回的是DOUBLE...
by Jelly_Goat @ 2019-02-04 23:52:20
建议不要使用Dev,C free等毒瘤@NaCly_Fish
by NaCly_Fish @ 2019-02-05 00:15:37
@Sai_0511 或许是CF评测鸡的锅?我在咕咕评测鸡上这么用都没事
by NaCly_Fish @ 2019-02-05 00:18:38
@╬ @chenyanming
但是我没有用cmath库,自己定义了pow函数