int main() { int p,q,i; int ct[30]; char pt[30]; int e,d,et,n,temp; printf("Enter Plain text : "); fgets(pt,30,stdin); printf("Enter prime No.s p,q :\n"); scanf("%d%d",&p,&q); n = p*q; et=(p-1)*(q-1); for(i=2;i<et;i++) { if(ex_gcd(et,i,1) == 1) { printf("%d\t",i); } } printf("\nSelect e value:"); scanf("%d",&e); temp = ex_gcd(et,e,2); d = et+temp; printf("\nPublic Key KU = {%d,%d}\n",e,n); printf("Private Key KR = {%d,%d}\n",d,n); printf("\nCipher Text : "); for(i=0;i<strlen(pt)-1;i++) { ct[i] = en_de(pt[i],e,n); printf(" %d",ct[i]); } printf("\n\nPlain Text After decrtion : "); for(i=0;i<strlen(pt)-1;i++) { printf("%c",en_de(ct[i],d,n)); } printf("\n"); return 0; }
int isConnectElevator(int i1, int i2) { long a, b, d, t, x, y; a = step[i1]; b = 0 - step[i2]; ex_gcd(a, b, &d, &x, &y); if ((initFloor[i2] - initFloor[i1]) % d != 0) { if (DEBUG) { printf("Elevator %d and %d a1 %d a2 %d return 0\n", i1, i2, step[i1], step[i2]); } return 0; } for (t = 0;; t++) { long x1 = x - step[i2] / d * t; long y1 = y - step[i1] / d * t; long f1 = initFloor[i1] + x1 * step[i1]; if (x1 >= 0 && f1 < maxFloor && y1 >= 0) { return 1; } if (f1 >= maxFloor || f1 < 0) break; } if (DEBUG) { printf("Elevator %d and %d return 0\n", i1, i2); } return 0; }
int main(){ int i,j,k; scanf("%I64d %I64d %I64d",&a,&b,&c); scanf("%I64d %I64d",&x1,&x2); scanf("%I64d %I64d",&y1,&y2); ans=0; if (a==0 && b==0){ if (c==0) ans=(x2-x1+1)*(y2-y1+1); }else if (a==0){ if (c%b==0 && c/b>=y1 && c/b<=y2) ans=x2-x1+1; }else if (b==0){ if (c%a==0 && c/a>=x1 && c/a<=x2) ans=y2-y1+1; }else{ long long g=gcd(a,b),p; c=-c; if (c%g==0){ p=c/g; ex_gcd(a,b,x0,y0); x0*=p; y0*=p; L=-1000000000; R=1000000000; check(x1-x0,x2-x0,b/g); check(y1-y0,y2-y0,-a/g); ans=max(ans,R-L+1); } } printf("%I64d\n",ans); return 0; }
void ex_gcd(int a, int b, int &x, int& y) { if (!b) { x = 1, y = 0; return; } ex_gcd(b, Mod(a, b), x, y); int t = x; x = y, y = t - a / b * y; }
inline int Gao(int a, int b, int c) { int t = gcd(abs(a), abs(b)); if (a < 0 || b < 0) t = -t; if (Mod(c, t) != 0) return 1521521521; int x = 0, y = 0; a /= t, b /= t, c /= t; ex_gcd(a, b, x, y); x *= c; while (x < 0) x += b; while (x > b) x -= b; return x; }
void ex_gcd(long a, long b, long * d, long * x, long * y) { if (b == 0) { *x = 1, *y = 0, *d = a; return; } long x1, y1; ex_gcd(b, a % b, d, &x1, &y1); *x = y1; *y = x1 - (a / b) * y1; }
long long ex_gcd(long long a,long long b,long long &x,long long &y){ if (b==0){ x=1;y=0; return a; } long long g=ex_gcd(b,a%b,x,y),tx=x; x=y; y=tx-(a/b)*y; return g; }
int ex_gcd(int a, int b, int *x, int *y) { if (b == 0) { *x = 1; *y = 0; return a; } else { int d = ex_gcd(b, a % b, x, y); int tmp = *x; *x = *y; *y = tmp - (a / b) * (*y); return d; } }
void modular_linear_equation(int a, int b, int n) { int x, y; int d = ex_gcd(a, b, &x, &y); if (b % d == 0) { int x0 = (x * (b/d)) % n; int i; for (i = 0; i < d; i++) { printf("%d\n", (x0 + (i * (n / d))) % n); } } else { printf("no solution\n"); } }
int check() { long gcd, m1, m2; ex_gcd(n1, n2, &gcd, &m1, &m2); if (n % gcd != 0) return 0; m1 *= n / gcd, m2 *= n / gcd; n2 /= gcd, n1 /= gcd; long c = ceil(-(double) m1 / n2), f = floor((double) m2 / n1); if (c > f) return 0; long cost = c1 * n2 - c2 * n1; if (cost * c < cost * f) step = m1 + n2 * c, initFloor = m2 - n1 * c; else step = m1 + n2 * f, initFloor = m2 - n1 * f; return 1; }
void ex_gcd(LL a,LL b,LL& d,LL& x,LL &y) { if(!b) { d=a; x=1; y=0; } else { ex_gcd(b,a%b,d,y,x); y-=x*(a/b); } }
LL inv(LL a,LL n) { LL d,x,y; ex_gcd(a,n,d,x,y); return (d==1)?(x+n)%n:-1; }