轮状病毒

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define R register
#define next kdjadskfj
#define debug puts("mlg")
#define mod 998244353
#define Mod(x) ((x%mod+mod)%mod)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
inline ll read();
inline void write(ll x);
inline void writeln(ll x);
inline void writesp(ll x);
struct node{
	ll h,num[300];
	bool operator <(node x)const{
		if(h!=x.h) return h<x.h;
		for(R ll i=h;i>=1;i--) if(num[i]!=x.num[i]) return num[i]<x.num[i];
	}
	inline void Write(){
		for(R ll i=h;i;i--) write(num[i]);putchar('\n');
	}
}a,b,c;
ll n;
node operator *(node x,node y){
	static node z;
	z.h=x.h+y.h-1;
	memset(z.num,0,sizeof z.num);
	for(R ll i=1;i<=x.h;i++){
		for(R ll j=1;j<=y.h;j++){
			z.num[i+j-1]+=x.num[i]*y.num[j];
			z.num[i+j]+=z.num[i+j-1]/10;
			z.num[i+j-1]%=10;
		}
	}
	if(z.num[z.h+1]) ++z.h;
	return z;
}
node operator +(node x,node y){
	static node z;
	z.h=max(x.h,y.h);
	memset(z.num,0,sizeof z.num);
	for(R ll i=1;i<=z.h;i++){
		z.num[i]+=x.num[i]+y.num[i];
		z.num[i+1]+=z.num[i]/10;
		z.num[i]%=10;
	}
	if(z.num[z.h+1]) ++z.h;
	return z;
}
node operator -(node x,node y){
	static node z;
	if(x<y) swap(x,y);
	z.h=x.h;
	memset(z.num,0,sizeof z.num);
	for(R ll i=1;i<=y.h;i++){
//		if(x.num[i]<y.num[i]) x.num[i]+=10,x.num[i+1]--;
		z.num[i]=x.num[i]-y.num[i];
	}
	for(R ll i=y.h+1;i<=x.h;i++){
		if(x.num[i]<0) x.num[i]+=10,--x.num[i+1];
		z.num[i]=x.num[i];
	}
	if(!z.num[z.h])--z.h;
	return z;
}
int main(){
	n=read();
	a.h=1;a.num[1]=1;
	b.h=1;b.num[1]=3;
	for(R ll i=2;i<=n;i++){
		c=a+b;
		a=b;b=c;
	}
	a=a*a;
	node d;
	d.h=1;d.num[1]=4;
	if(!(n&1))a=a-d;
	a.Write();
}
inline ll read(){ll x=0,t=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') t=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*t;}
inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x<=9){putchar(x+'0');return;}write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x);putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
posted @ 2020-08-15 08:16  月落乌啼算钱  阅读(125)  评论(0编辑  收藏  举报