Ultraviolet A 684-integral Determinant
Question Link
Question: Give a determinant and find the value.
Train of Thought: Use the column subtraction in linear algebra, and then continuously reduce the order, that is, use the score to write
Code:
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int n = 35; long gcd (long a, long B) {If (! B) return a; return gcd (B, A % B);} long lcm (long a, long B) {A = A/gcd (A, B) * B; if (a <0) A =-A; return a;} struct fraction {long a, B; fraction () {A = 0; B = 1 ;} fraction (long x) {A = x; B = 1;} fraction (long X, long y) {A = x; B = y;} void deal () {If (B <0) {B =-B; A =-A;} long K = gcd (a, B); If (k <0) k =-K; A/= K; B/= K;} fraction operator + (F Raction p) {fraction ans; ans. B = lcm (B, P. b); ans. A = ans. b/B * A + ans. b/P. B * P. a; ans. deal (); Return ans;} fraction operator-(fraction p) {fraction ans; ans. B = lcm (B, P. b); ans. A = ans. b/B * A-ans. b/P. B * P. a; ans. deal (); Return ans;} fraction operator * (fraction p) {fraction ans; ans. A = A * P. a; ans. B = B * P. b; ans. deal (); Return ans;} fraction operator/(fraction p) {fracti On ans; ans. A = A * P. b; ans. B = B * P. a; ans. deal (); Return ans;} void operator = (long x) {A = x; B = 1;} void print () {printf ("% LLD/% LLD \ n", a, B) ;}}; int N; struct Col {fraction R [N];} C [N]; long long solve () {int now = 1; fraction x = 1; for (INT now = 1; now <n; now ++) {int flag = 1; for (INT I = now-1; I <n; I ++) {If (C [I]. R [now-1]. a) {swap (C [now-1], C [I]); if (I! = Now-1) x = x * fraction (-1); flag = 0; break;} If (FLAG) return 0; flag = 1; for (INT I = now; I <n; I ++) {fraction K = C [I]. R [now-1]/C [now-1]. R [now-1]; for (Int J = now-1; j <n; j ++) C [I]. R [J] = C [I]. R [J]-(fraction (k) * C [now-1]. R [J]);} X = x * C [now-1]. R [now-1];} return (x * C [n-1]. R [n-1]). a;} int main () {While (~ Scanf ("% d", & N) {If (n = 0) {printf ("* \ n"); break;} long num; for (INT I = 0; I <n; I ++) {for (Int J = 0; j <n; j ++) {scanf ("% LLD ", & num); C [J]. R [I] = num;} printf ("% LLD \ n", solve ();} return 0 ;}