标签:div tab 输出 ota 开心 lan pst pos type
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 114412 | Accepted: 23446 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
1 #include <iostream> 2 using namespace std; 3 4 long long extgcd(long long a, long long b, long long &x, long long &y) 5 { 6 long long d, t; 7 if (b == 0) 8 { 9 x = 1; 10 y = 0; 11 return a; 12 } 13 d = extgcd(b, a % b, x, y); 14 t = x - a / b * y; 15 x = y; 16 y = t; 17 return d; 18 } 19 int main() 20 { 21 long long x, y, m, n, L, X, Y, d, r; 22 cin >> x >> y >> m >> n >> L 23 d = extgcd(n - m, L, X, Y); 24 r = L / d; 25 if ((x - y) % d) cout << "Impossible" << endl; 26 else cout << ((x - y) / d * X % r + r) % r << endl; 27 return 0; 28 }
1 #include <cstdio> 2 typedef long long LL; 3 4 LL gcd( LL a, LL b ) 5 { 6 return b==0?a:gcd( b, a%b ); 7 } 8 void exgcd( LL a, LL b, LL &x, LL &y ) 9 { 10 if( b==0 ) 11 { 12 x=1, y=0; 13 return ; 14 } 15 exgcd( b, a%b, x, y ); 16 LL t=x; 17 x=y; 18 y=t-a/b*y; 19 } 20 int main( ) 21 { 22 LL x, y, m, n, l; 23 LL a, b, c, k1, k2, r; 24 while(scanf( "%lld%lld%lld%lld%lld", &x, &y, &m, &n, &l )!= EOF) 25 { 26 a=n-m; c=x-y; r=gcd(a,l); 27 if(c%r) 28 { 29 printf("Impossible"); 30 continue; 31 } 32 a/=r; l/=r; c/=r; 33 exgcd(a, l, k1, k2); 34 LL t = c*k1/l; 35 k1 = c*k1-t*l; 36 if(k1<0) k1 += l; 37 printf( "%lld\n", k1 ); 38 } 39 return 0; 40 }
标签:div tab 输出 ota 开心 lan pst pos type
原文地址:http://www.cnblogs.com/mjtcn/p/6850408.html