Cod sursa(job #3161790)

Utilizator BucsMateMate Bucs BucsMate Data 27 octombrie 2023 23:03:09
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream input("euclid3.in");
    ofstream output("euclid3.out");
    int a, b, c, k=1, tempa, tempb, temp;
    input>>a;
    while (input>>a) {
        input>>b>>c;
        tempa=a;
        tempb=b;
        while (tempb!=0) {
            temp=tempa;
            tempa=tempb;
            tempb=temp%tempb;
        }
        if(c%tempa==0) {
            if(c%a==0){
                output<<c/a<<" "<<0<<endl;
            } else if(c%b==0){
                output<<0<<" "<<c/b<<endl;
            } else{
                while ((c-k*a)%b != 0){
                    k=k+1;
                }
                output<<k<<" "<<(c-k*a)/b<<endl;
            }
        } else
            output<<0<<" "<<0<<endl;

    }
    return 0;
}