zoukankan      html  css  js  c++  java
  • 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
    */
    
  • 相关阅读:
    为什么要用泛型呢
    sql语句优化
    SQL Server 2008 问题——已成功与服务器建立连接,但是在登录过程中发生错误。
    CHECKFORILLEGALCROSSTHREADCALLS = FALSE
    数据类型 text 和 varchar 在 add 运算符中不兼容
    js中数组对象去重的方法
    json字符串、json对象、数组之间的转换
    如何用jQuery获得select的值
    SQL Server 性能调优
    TSQL 数据类型转换
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11368709.html
Copyright © 2011-2022 走看看