欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

[扩展欧拉函数]luoguP1516青蛙的约会

程序员文章站 2022-05-06 20:17:53
题目题目链接:https://www.luogu.com.cn/problem/P1516思路好麻烦啊不想写呜呜呜数论怎么这么麻烦代码#include#include#include#include#include#include#include#include

题目

[扩展欧拉函数]luoguP1516青蛙的约会
题目链接:https://www.luogu.com.cn/problem/P1516

思路

好麻烦啊不想写呜呜呜数论怎么这么麻烦

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
int exgcd(int a,int b,int &x1,int &y1){
	if(b==0){
		x1=1;
		y1=0;
		return a;
	}
	int g=exgcd(b,a%b,x1,y1);
	int temp=x1;
	x1=y1;
	y1=temp-(a/b)*y1;
	return g;	
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int x,y,n,m,l;
	cin>>x>>y>>n>>m>>l;
	int a=x-y,b=m-n;
	if(b<0){
		a=-a;
		b=-b;
	}
	int x1=0,x2=0;
	int gcd=exgcd(b,l,x1,x2);
//	cout<<gcd<<endl;
	if(a%gcd!=0) cout<<"Impossible"<<endl;
	else cout<<((x1*(a/gcd))%(l/gcd)+(l/gcd))%(l/gcd)<<endl;
    return 0;
}

本文地址:https://blog.csdn.net/kosf_/article/details/107397118