#include<iostream> using namespace std; long long exgcd( long long a, long long b, long long &x, long long &y ) { if( b == 0 ) { x = 1; y = 0; return a; } long long d = exgcd( b, a%b, x, y ); long long temp = x; x = y; y = temp -(a/b)*y; return d; } int main() { long long x, y, m, n, l; long long t, p; long long M, N; while (cin >> x>> y>> m>> n>> l) { M = exgcd( n-m, l, t, p ); if( ( x - y )%M || (n == m) ) { cout << "Impossible"<<endl; }else { N = l/M; t = t*( ( x - y )/M ); t = ( t%N + N )%N; cout << t<< endl; } } return 0; }
扩展欧几里德+由于return的 d 的问题 wrong了好多次+贴上
小结:我们要将现实问题抽象成符号语言(公式),我们还要找到最符合编程实现的公式,这就是学计算机和学数学的区别《《