• LuoguP1516 青蛙的约会 (Exgcd)


    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
    #define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
    
    #define ON_DEBUGG
    
    #ifdef ON_DEBUGG
    
    #define D_e_Line printf("
    ----------
    ") 
    #define D_e(x) cout << (#x) << " : " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt", "r", stdin)
    
    #else
    
    #define D_e_Line ;
    #define D_e(x) ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    using namespace std;
    struct ios{
    	template<typename ATP>inline ios& operator >> (ATP &x){
    		x = 0; int f = 1; char ch;
    		for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    		while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
    		x *= f;
    		return *this;
    	}
    }io;
    
    #define int long long
    inline int Gcd(int a, int b){
    	while(b ^= a ^= b ^= a %= b);
    	return a;
    //	if(!b) return a;
    //	return Gcd(b, a % b);
    }
    inline void Exgcd(int a, int b, int &x, int &y){
    	if(!b)
    		x = 1, y = 0;
    	else
    		Exgcd(b, a % b, y, x), y -= x * (a / b);
    }
    #undef int 
    int main(){
    #define int long long
    	int a, b, m, n, L;
    	io >> a >> b >> m >> n >> L;
    	int A = n - m, B = L, C = a - b; 
    	if(A < 0){
    		A = -A, C = -C;
    	}
    	int r = Gcd(A, B);
    	if(C % r){
    		printf("Impossible");
    		return 0;
    	}
    	A /= r, B /= r, C /= r;
    	//D_e(B);
    	int x, y;
    	Exgcd(A, B, x, y);
    	
    //	cout << x * C << endl;
    //	cout << x * C % B << endl;
    //	cout << x * C % B + B << endl;
    	printf("%lld", (x * C  % B + B) % B);
    	
    	return 0;
    }
    /*
    (n - m) * x + L * y = a - b
    
    A = n - m
    B = L
    C = A - B
    */
    
  • 相关阅读:
    attr系列
    面对对象中的反射
    Python中的内置函数(比较重要的)
    过滤莫文件夹下所有文件和子文件夹中的文件,并把路径打印出-----面对过程的编程
    python中字典的几个方法介绍
    python中字符串的几个方法介绍
    python中列表与元组
    win7上python2.7连接mysql数据库
    练习-三级菜单
    练习-模拟商城购物车
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11368709.html
Copyright © 2020-2023  润新知