Skip to content

Instantly share code, notes, and snippets.

@MagallanesFito
Last active January 5, 2016 09:51
Show Gist options
  • Save MagallanesFito/e89d425bd4dafa7cbb6c to your computer and use it in GitHub Desktop.
Save MagallanesFito/e89d425bd4dafa7cbb6c to your computer and use it in GitHub Desktop.
solucion Agente A, Heroe Nacional. Problema preselectivo
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
ULL n,t,a,b,d,suma;
int main(){
cin>>n;
cin>>t;
suma = 0;
while(n--){
cin>>a>>b;
d = __gcd(a,b);
if(d == 1){
suma+=min(a,b)+1;
continue;
}
while(a!=0 && b!=0){
a-=d;
b-=d;
suma++;
if(b == 0 && a!=0){
a=0;
suma++;
}
if(a == 0 && b!=0){
b = 0;
suma++;
}
}
}
if(suma-1 > t) cout << "El Agente A no sera heroe nacional, el Doctor B destruira su pais";
else cout << suma-1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment