您的位置:首页 > 其它

bzoj4002

2015-08-24 09:43 260 查看
http://www.lydsy.com/JudgeOnline/problem.php?id=4002

好吧,完全不会做,在考场只能爆零。

膜拜PoPoQQQ大神

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj

using namespace std;

typedef unsigned long long ULL;
typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP;

#define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define fill(a,l,r,v) fill(a+l,a+r+1,v)
#define re(i,a,b)  for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k))

template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;}

const DB EPS=1e-9;
inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;}
const DB Pi=acos(-1.0);

inline int gint()
{
int res=0;bool neg=0;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return 0;
if(z=='-'){neg=1;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=0;bool neg=0;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return 0;
if(z=='-'){neg=1;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar());
return (neg)?-res:res;
}

const ULL Mod=7528443412579576937;

ULL b,d,n;
ULL res;

inline ULL cheng(ULL a,ULL b)
{
ULL res=0;
for(;b!=0;b>>=1){if(b&1)res=(res+a)%Mod;a=(a<<1)%Mod;}
return res;
}

struct Tmatrix
{
int n,m;
ULL v[3][3];
inline void clear(){n=m=0;mmst(v,0);}
inline friend Tmatrix operator *(Tmatrix a,Tmatrix b)
{
Tmatrix c;c.clear();
int i,j,k;
c.n=a.n;c.m=b.m;
re(i,1,c.n)
re(j,1,c.m)
re(k,1,a.m)
c.v[i][j]=(c.v[i][j]+cheng(a.v[i][k],b.v[k][j]))%Mod;
return c;
}
};

inline Tmatrix power(Tmatrix a,ULL k)
{
Tmatrix x;x.clear();
x.n=x.m=2;
x.v[1][1]=x.v[2][2]=1;
while(k){if(k&1)x=x*a;a=a*a;k>>=1;}
return x;
}

Tmatrix A;

int main()
{
freopen("bzoj4002.in","r",stdin);
freopen("bzoj4002.out","w",stdout);
b=gll();d=gll();n=gll();
if(n==0)
cout<<"1"<<endl;
else
{
A.clear();
A.n=A.m=2;
A.v[1][1]=b;A.v[1][2]=(d-b*b)/4;
A.v[2][1]=1;A.v[2][2]=0;
A=power(A,n-1);
res=(cheng(A.v[1][1],b)+cheng(A.v[1][2],2))%Mod;
if(b*b!=d && !(n&1))res--;
res=(res%Mod+Mod)%Mod;
cout<<res<<endl;
}
return 0;
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: