Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created November 16, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chermehdi/bd84483fe1d84f1f80f61105c63303ed to your computer and use it in GitHub Desktop.
Save chermehdi/bd84483fe1d84f1f80f61105c63303ed to your computer and use it in GitHub Desktop.
A game of Peace solution
import java.io.*;
import java.util.*;
/**
* @author Mehdi Maick
**/
public class scorify {
public static void solve(Scanner fs, PrintWriter pw) {
int t = fs.nextInt();
int tc= 1;
while(t-- > 0){
int x = fs.nextInt();
int n = fs.nextInt();
int y = fs.nextInt();
int m= fs.nextInt();
long sx = x, sy = 0;
for(int i = 0; i < n; i++){
if(sx > sy){
sy += sx;
}else{
sx += sy;
}
}
if(sx < sy){
sy += y;
}else{
sx += y;
}
pw.println("Case "+(tc++)+": "+gcd(sy,sx));
}
}
public static long gcd(long a, long b){
if (a == 0)
return b;
return gcd(b%a, a);
}
public static void main(String[] args){
Scanner fs = new Scanner(System.in);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
solve(fs, pw);
pw.flush();
pw.close();
fs.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment