http://acm.hdu.edu.cn/showproblem.php?pid=1031
http://www.cnblogs.com/chanme/p/3861766.html
http://m.blog.csdn.net/blog/tjdrn/9329531
http://blog.csdn.net/xuezhongfenfei/article/details/9822173
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2619
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <algorithm> using namespace std; #define root 1,n,1 #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define lr rt<<1 #define rr rt<<1|1 typedef long long LL; typedef pair<int,int>pii; #define X first #define Y second const int oo = 1e9+7; const double PI = acos(-1.0); const double eps = 1e-6 ; const int N = 55; #define mod 200000000000000003LL //需要的是素数 #define dif 100000000000000000LL //偏移量,使得数都是整数,方便移位乘法 LL Mod(LL x) { //加法取模,防止超__int64 if (x >= mod) return x - mod; return x; } LL mul(LL a, LL b) { //乘法取模,用移位乘法,防止超__int64 LL res; for (res = 0; b; b >>= 1) { if (b & 1) res = Mod(res + a); a = Mod(a + a); } return res; } void e_gcd( LL a , LL b , LL &d , LL &x , LL &y ) { //拓展的欧几里德定理,求ax+by=gcd(a,b)的一个解 if( !b ){ d = a , x = 1 , y = 0 ; return ; } e_gcd( b , a%b , d , y , x ); y -= x*(a/b); } LL inv( LL a , LL n ){ //求逆,用于除法取模 LL d,x,y ; e_gcd(a,n,d,x,y); return ( x % n + n ) % n ; } LL A[N][N] , g[N][N]; int n ; void Gauss() { //高斯消元 for( int i = 0 ; i < n ; ++i ) { int r = i ; for( int j = i ; j < n ; ++j ) { if( g[j][i] ) { r = j ; break ; } } if( r != i ) for( int j = 0 ; j <= n ; ++j ) swap( g[i][j] , g[r][j] ) ; LL INV = inv( g[i][i] , mod ); for( int k = i + 1 ; k < n ; ++k ) { if( g[k][i] ) { LL f = mul( g[k][i] , INV );//相当于g[k][i]/g[i][i]%mod; for( int j = i ; j <= n ; ++j ) { g[k][j] -= mul( f , g[i][j] ); g[k][j] = ( g[k][j] % mod + mod ) % mod ; } } } } for( int i = n - 1 ; i >= 0 ; --i ){ for( int j = i + 1 ; j < n ; ++j ){ g[i][n] -= mul( g[j][n] , g[i][j] ) , g[i][n] += mod , g[i][n] %= mod ; } g[i][n] = mul( g[i][n] , inv( g[i][i] , mod ) ); } } void Run() { scanf("%d",&n); memset( g , 0 , sizeof g ); for( int i = 0 ; i <= n ; ++i ) { for( int j = 0 ; j < n ; ++j ) { scanf("%I64d",&A[i][j]); A[i][j] += dif ; //偏移diff } } for( int i = 0 ; i < n ; ++i ){ for( int j = 0 ; j < n ; ++j ){ g[i][j] = Mod( A[n][j] - A[i][j] + mod ); g[i][j] = mul( g[i][j] , 2 ) ; g[i][n] = Mod( g[i][n] + mul( A[n][j] , A[n][j] ) ); g[i][n] = Mod( g[i][n] - mul( A[i][j] , A[i][j] ) + mod ); } } Gauss(); printf("%I64d",g[0][n]-dif); //减去先前偏移的值 for( int i = 1 ; i < n ; ++i ){ printf(" %I64d",g[i][n]-dif); }puts(""); } int main() { int cas = 1 , _ ; scanf("%d",&_ ); while( _-- ){ printf("Case %d:\n",cas++); Run(); } }