| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 96667 | Accepted: 18091 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
一直都不太会用,扩展欧几里得,,分析就不详细写啦,具体参照这篇博客
AC代码:
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std;
LL x, y, n, m, L;
LL gcd(LL a, LL b) {
return b == 0 ? a : gcd(b, a % b);
}
void exgcd(LL a, LL b, LL& x, LL& y) {
if(b == 0) {
x = 1; y = 0;
}
else {
exgcd(b, a % b, y, x);
y -= x * (a / b);
}
}
int main() {
while(scanf("%I64d %I64d %I64d %I64d %I64d", &x, &y, &m, &n, &L) != EOF) {
LL a = m - n;
LL b = L;
LL c = gcd(a, b);
LL d = y - x;
if(m == n) {
printf("Impossible\n");
continue;
}
if(d % c != 0) {
printf("Impossible\n");
continue;
}
LL p, q;
exgcd(a, b, p, q);
printf("%I64d\n", (p * (d / c) % b + b) % b);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u014355480/article/details/47083569