1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
import java.io.*; import java.util.*; public class Main {
static long[] s,l,f,ans; static String[] sh,sr; final static int maxn=201315; final static long mod=530600414L; static long mul_mod(long n, long m, long mod) { long ans = 0L; n %= mod; while (m > 0L) { if ((m & 1L) > 0L) ans = (ans + n) % mod; m >>= 1; n = (n + n) % mod; } return ans; } static void init(){ s=new long[maxn]; l=new long[maxn]; f=new long[maxn]; ans=new long[maxn]; sh=new String[maxn]; sr=new String[maxn]; s[1]=s[2]=0;s[3]=1;s[4]=3; f[1]=f[2]=0;f[3]=f[4]=1; l[1]=1;l[2]=2;l[3]=3;l[4]=5; ans[1]=ans[2]=ans[3]=ans[4]=0; sh[3]=new String("cf");sr[3]=new String("ff"); sr[4]=new String("ff");sr[4]=new String("ff"); } static long solve(int n){ long res=0L; if (n<5) return res; if (ans[n]>0L) return ans[n]; res+=solve(n-2); res+=solve(n-1); sh[n]=sh[n-2];sr[n]=sr[n-1]; boolean has=false; if (sr[n-2].compareTo("cf")==0&&sh[n-1].charAt(0)=='f'){ has=true;s[n]+=l[n-2]-1; res-=s[n-2]; res+=mul_mod((l[n-2]-1),f[n-2],mod); } if (sr[n-2].charAt(1)=='c'&&sh[n-1].compareTo("ff")==0){ has=true;s[n]+=l[n-2]; res-=s[n-2]; res+=mul_mod(l[n-2],f[n-2],mod); } s[n]+=(s[n-2]+s[n-1]+mul_mod(l[n-2],f[n-1],mod))%mod;s[n]%=mod; f[n]=has?f[n-2]+f[n-1]+1:f[n-2]+f[n-1];f[n]%=mod; l[n]=l[n-2]+l[n-1];l[n]%=mod; res-=mul_mod(s[n-2],f[n-1],mod); res+=mul_mod(s[n-1]+mul_mod(l[n-2],f[n-1],mod),f[n-2],mod); while(res<0L) res+=mod; res%=mod; ans[n]=res; return res; } public static void main(String[] args) throws IOException{ InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(),cas=0; init(); for(int i=5;i<maxn;i++) solve(i); while(T-->0){ long k=solve(in.nextInt()); out.println("Case #"+(++cas)+": "+k); } out.flush(); out.close(); } }
|