G17 不定方程 扩展欧几里得算法

 视频链接:https://www.bilibili.com/video/BV1rD4y1C7qg/

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
    
int exgcd(int a,int b,int &x,int &y){
  if(b == 0) {x=1, y=0; return a;}
  int x1, y1, d;
  d = exgcd(b, a%b, x1, y1);
  x = y1, y = x1-a/b*y1;
  return d;
}
int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c;
  int d = exgcd(a,b,x,y);
  if(c%d == 0) 
    printf("%d %d",c/d*x,c/d*y);
  else puts("none");
  return 0;
}

 

练习

Luogu P1516 青蛙的约会

posted @ 2022-09-26 21:26  董晓  阅读(538)  评论(1编辑  收藏  举报