According to this law to find out the constant modulus will be negative. Requires (Ans+mod)%mod to be a positive number.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define LL __int64const ll Mod=530600414;const int maxn=201399;ll w[maxn],ans[maxn],num[maxn],len[maxn];void init () {int n=201318,i;len[1]=1; Len[2]=2;for (i=3;i<=n;i++) len[i]= (Len[i-1]+len[i-2])%mod;for (i=0;i<=4;i++) ans[0]=0;num[0]=0;num[1]=0;num [2]=0;w[4]=3;w[3]=1;num[3]=1;num[4]=1;for (i=5;i<=n;i++) {ans[i]= ((ans[i-1]+ans[i-2])%mod+ ((Len[i-2]*num[i-2] %mod-w[i-2])%mod) *num[i-1]%mod+w[i-1]*num[i-2]%mod)%mod;num[i]= (Num[i-1]+num[i-2])%mod;w[i]= (Num[i-1]*len[i-2] %mod+ (W[i-1]+w[i-2])%mod)%mod;}} int main () {int i,j,n,t;init (), while (scanf ("%d", &t) ==1) {int Cas=1;while (t--) {scanf ("%d", &n);p rintf ("Case #% D:%i64d\n ", cas++, (Ans[n]+mod)%mod);}} return 0;}
HDU 5459 Jesus is here Shenyang online game