Microcomputer principle: 8086 arithmetic instruction, jump instruction
Operating system: Process scheduling algorithm, banker algorithm
Python: Lists, dictionaries, classes and objects
Algorithm: Number theory (extended Euclidean, unary linear congruence equation set)
In the Hihocoder study these two, one dollar linear that question greatest common divisor variable uses to write disorderly, check code ability still need to strengthen ...
Number theory is very stressful.
Extended Euclid:
#include <stdio.h>#include <utility>using namespace std;typedef Long Long ll;typedef pair<ll,ll> xy;xy ans,cst (0,1 ); ll gcd (ll X,ll y) {if (x %y==0) return y; else return gcd (y,x% y);} XY EXTEND_GCD (ll a,ll b) {if (a%b==0) return CST; XY TEMPXY=EXTEND_GCD (b,a% b); xy x_y; x_y.first= Tempxy. Second x_y.second=tempxy.first-a/b* Tempxy.second; return x_y;} int Main () {ll s1,s2,v1,v2,m,a,b,c,judge; scanf ("%lld%lld%lld%lld%lld",&s1,&s2,&v1,&v2,& m); a=v1-v2;b=m;c=s2- s1; if (a<0) a= (a+m)% m; judge= gcd (A, b); if (c%judge!=0) {printf (" -1\n"); return 0 ;} a/= judge; b/= judge; c/= judge; ans= EXTEND_GCD (A, b); ans.first= (ans.first*c)% B; while ( ans.first<0) ans.first+= b; printf ("%lld\n" , Ans.first); return 0 ;}
One-element linear congruence Equation Group:
#include <stdio.h>using namespaceStd;typedef Long LongLl;structpair{ll x, y; Pair () {} pair (ll xx,ll yy) {x=xx;y=yy }};ll m[1010],r[1010];p Air ans,cst (0,1 ), LL gcd (ll X,ll y) {if (x%y==0) return y; else return gcd (y,x% y);} Pair EXTEND_GCD (ll A,ll b) {if (a%b==0) return CST; pair TEMP=EXTEND_GCD (b,a% b); pair xy; xy.x= temp.y; x y.y=temp.x-a/b* temp.y; return XY;} int Main () {ll n,i,r,m,a,b,c,judge; scanf ("%lld", & n); for (i=1;i<=n;i++ ) scanf ("%lld%lld", &m[i],& R[i]); R=R[1]; M=m[1 ]; pair ans; for (i=2;i<=n;i++ ) {a=m;b=m[i];c=r[i]- R; judge= gcd (A, b); if (c%judge!=0) { printf (" -1\n"); return 0 ;} a/=judge;b/=judge;c/= judge; ans= EXTEND_GCD (A, b); ans.x= (c*ans.x)% b; r=r+m* ans.x; m=m/judge* M[i]; r=r% m;} while (r<0) r+= M; printf ("%lld\n" , R); return 0 ;
2016-05-23