UVA 10673 扩展欧几里得
题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整
题解:扩展欧几里得
//meek///#include<bits/stdc++.h> #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <set> #include <stack> #include <sstream> #include <vector> using namespace std ; #define mem(a) memset(a,0,sizeof(a)) #define pb push_back #define fi first #define se second #define MP make_pair typedef long long ll; const int N = 110; const int inf = 99999999; const int mod= 1000000007; ll ExpGcd(ll a,ll b,ll &x,ll &y) { ll temp,p; if(b==0) { x=1; y=0; return a; } p=ExpGcd(b,a%b,x,y); temp=x; x=y; y=temp-(a/b)*y; return p; } int main() { int T; scanf("%d",&T); while(T--) { ll x,k,X,Y; scanf("%lld%lld",&x,&k); ll a = floor(1.0*x/k); ll b = ceil(1.0*x/k); ll d = ExpGcd(a,b,X,Y); //cout<<X<<" "<<Y<<endl; //if(X<0) X=(X%b+b)%b; X *= x/d; Y *= x/d; printf("%lld %lld\n",X,Y); } return 0; }