Created
November 16, 2016 20:04
-
-
Save chermehdi/bd84483fe1d84f1f80f61105c63303ed to your computer and use it in GitHub Desktop.
A game of Peace solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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