High Precision +GCD
Well...... Stripping GCD can actually count:
\[GCD (A, b) = \begin{cases} A & b=0 \ 2*gcd (\frac{a}{2},\frac{b}{2}) & A\mod 2=0,b \mod 2=0 \ GCD (\frac{a}{2},b) & a\mod 2=0,b \mod 2=1 \ GCD (a,\frac{b}{2}) & A\mod 2=1,b \mod 2=0 \ GCD (b,a-b) & Else \end{cases} \]
However, Windows is only 8M down the stack of the pit dad ah ... Local cannot run big data at all ... Then hang on ...
Had to change most of the operations to void type, and to pass the reference, and then change the GCD process to the global variables to operate ... does not pass parameters ...
All sorts of disorderly engage in a way finally is past this template problem ... sad
1 /**************************************************************2 problem:18763 User:tunix4 language:c++5 result:accepted6 time:1860 Ms7 memory:1556 KB8 ****************************************************************/9 Ten //Bzoj 1876 One#include <cstdio> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back - using namespacestd; +typedefLong LongLL; AInlineintGetint () { at intR=1, v=0;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; - for(; isdigit (ch); Ch=getchar ()) v=v*Ten-'0'+ch; - returnr*v; - } - Const intn= .; in /*******************template********************/ - to structbint{ + intV[n]; - intl; theBint () {l=0; memset (V,0,sizeofv);} * int&operator[] (intx) {returnv[x];} $ }a,b,r,t;Panax Notoginseng - Const intlimit=1000000000; the //const LL LIMIT=10000000000000000LL; + //1e16 A voidprint (bint a) { theprintf"%d", A[a.l]); +D (i,a.l-1,1) printf ("%09d", A[i]); -Puts""); $ } $Bintoperator-(bint A,bint b) { -F (I,1, A.L) { -a[i]-=B[i]; the if(a[i]<0) a[i]+=limit,a[i+1]--; - }Wuyi while(A.l && a[a.l]==0) a.l--; the returnA; - } Wu voidDiv2 (bint&a) { -F (I,1, A.L) { About if(a[i]&1) a[i-1]+=limit/2; $a[i]>>=1; - } - while(A.l && a[a.l]==0) a.l--; - } A + voidMul2 (Bint &a) { theD (I,A.L,1){ -a[i]<<=1; $a[i+1]+=a[i]/Limit; thea[i]%=Limit; the } the while(a[a.l+1]>0) a.l++; the } - BOOL operator<(bint A,bint b) { in if(A.L!=B.L)returna.l<B.L; theD (I,A.L,1){ the if(A[i]!=b[i])returna[i]<B[i]; About } the return 0; the } the voidgcd () { + if(b.l==0){ -R=a;return; the }Bayi if(! (a[1]&1) &&! (b[1]&1)){ theDiv2 (a), div2 (b); GCD (); MUL2 (R);return; the } - if(! (a[1]&1) && (b[1]&1)){ -Div2 (a); GCD ();return; the } the if((a[1]&1) &&! (b[1]&1)){ theDiv2 (b); GCD ();return; the } - if(a<b) Swap ( A, a); theT=b; B=a-b; A=T; the gcd (); the }94 Chars1[20000],s2[20000]; the the intMain () { the #ifndef Online_judge98Freopen ("1876.in","R", stdin); AboutFreopen ("1876.out","W", stdout); - #endif101scanf"%s%s", s1+1, s2+1);102 intL1=strlen (s1+1), L2=strlen (s2+1);103a.l=l1/9+BOOL(l1%9);104b.l=l2/9+BOOL(l2%9); theF (I,1, A.L) {106 intK1=max (1, l1-i*9+1), k2=l1-(i-1)*9;107F (J,K1,K2) a[i]=a[i]*Ten+s1[j]-'0';108 }109F (I,1, B.L) { the intK1=max (1, l2-i*9+1), k2=l2-(i-1)*9;111F (J,K1,K2) b[i]=b[i]*Ten+s2[j]-'0'; the }113 gcd (); the print (r); the return 0; the}
View Code 1876: [SDOI2009]SUPERGCD time limit:4 Sec Memory limit:64 MB
submit:1826 solved:589
[Submit] [Status] [Discuss] Descriptionsheng Bill has an amazing mental arithmetic ability, and can even use the brain to figure out two huge numbers of gcd (greatest common divisor)! So he often contests with others to calculate gcd. One day Sheng Bill very arrogant to find you, and asked to play with you, but lost to Sheng Bill is not very embarrassing! So you decided to write a program to teach him. Input is a total of two lines: the first line: a number A. Second line: a number B. An output row that represents the greatest common divisor of a and B. Sample Input12
54
Sample Output6
HINT
For 20% of data, 0 < A, b≤10 ^ 18.
For 100% of data, 0 < A, b≤10 ^ 10000.
Source
Day1
[Submit] [Status] [Discuss]
"Bzoj" "1876" "SDOI2009" SUPERGCD