标签:次数 end poj string its 位置 with span 判断
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
就是一个exgcd板题 关键在于推公式
exgcd就是用特解求全部解 找出一个特殊情况就好了
注意答案为负数的情况
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <bitset> #define rap(i, a, n) for(int i=a; i<=n; i++) #define rep(i, a, n) for(int i=a; i<n; i++) #define lap(i, a, n) for(int i=n; i>=a; i--) #define lep(i, a, n) for(int i=n; i>a; i--) #define rd(a) scanf("%d", &a) #define rlld(a) scanf("%lld", &a) #define rc(a) scanf("%c", &a) #define rs(a) scanf("%s", a) #define rb(a) scanf("%lf", &a) #define rf(a) scanf("%f", &a) #define pd(a) printf("%d\n", a) #define plld(a) printf("%lld\n", a) #define pc(a) printf("%c\n", a) #define ps(a) printf("%s\n", a) #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 10010, INF = 0x7fffffff; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); } LL exgcd(LL a, LL b, LL& d, LL& x, LL& y) { if(!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); } } int main() { LL a, b, d, x, y; LL _x, _y, m, n, l; cin >> _x >> _y >> m >> n >> l; if((_x - _y) % gcd(l, n - m)) return puts("Impossible"); exgcd(n - m, l, d, x, y); x *= (_x - _y) / d; x = (x % l + l) % l; cout << x << endl; return 0; }
标签:次数 end poj string its 位置 with span 判断
原文地址:https://www.cnblogs.com/WTSRUVF/p/10281418.html