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
    */
    
  • 相关阅读:
    建造者模式
    设计模式的思考
    与公司开票接口对接的设计
    读EntityFramework.DynamicFilters源码_心得_设计思想_04
    读EntityFramework.DynamicFilters源码_心得_单元测试03
    读EntityFramework.DynamicFilters源码_心得_示例演示02
    带你看懂Dictionary的内部实现
    Working With Taxonomy Field in CSOM
    SharePoint 2013 REST 以及 OData 基础
    SharePoint API如何处理时区问题
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11368709.html
Copyright © 2011-2022 走看看