1.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10104 - Euclid Problem
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=13&problem=1045&mosmsg=Submission+received+with+ID+7043086
*
* @author Andre Wolfram
* @author Christoph Miesel
* @author Robert Seilbeck
* @version 1.0, 04/01/2009
*
* Status : Accepted
* Runtime 2.540
*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {

/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line;
int x = 0;
int lastx = 1;
int y = 1;
int lasty = 0;

while ((line = reader.readLine()) != null) {
StringTokenizer st=new StringTokenizer(line," ");

int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());

x = 0;
lastx = 1;
y = 1;
lasty = 0;
//Algorithmus nach Wikipedia http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
while (b != 0){
int quotient = a / b;

int temp = b;
b = a % b;
a = temp;

temp = x;
x = lastx-quotient*x;
lastx = temp;

temp = y;
y = lasty-quotient*y;
lasty = temp;
}
System.out.printf(lastx+" "+lasty+" "+a+"\n");

}
}

}


2.


/**
* Angewandte Mathematik SS 09
10104 Euclid Problem
* UVa Status: Accepted, 21.03.2009
* Run Time: 0.290
* Programming Language: C
* @author Doina Logofatu logofatu@hm.edu
*/

#include <stdio.h>
#include <math.h>

int main() {

long a, b;
long x, y, lastx, lasty, temp, q;

while( scanf("%ld %ld", &a, &b) == 2){
x = lasty = 0;
y = lastx = 1;
while(b){
temp = b;
q = a / b;
b = a % b;
a = temp;

temp = x;
x = lastx - q*x;
lastx = temp;

temp = y;
y = lasty - q*y;
lasty = temp;
}
printf("%ld %ld %ld\n", lastx, lasty, a);
}

return 0;

}