Last active
July 17, 2016 13:27
-
-
Save Jack-Saleem/66f82f52dc80104d4291a706945569e0 to your computer and use it in GitHub Desktop.
Codeforces 360A VasyaAndSocks program in java
This file contains hidden or 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.util.ArrayList; | |
import java.util.Scanner; | |
public class VasyaAndSocks | |
{//same as NewYearCandles | |
ArrayList<Integer> r = new ArrayList<Integer>(); | |
int x = 0; | |
int socks(int a , int b) | |
{ | |
int counter = 0; | |
while(a/b != 0){ | |
counter++; | |
x += a/b; | |
r.add(a%b); | |
a = a/b; | |
if(a/b == 0) | |
r.add(a); | |
} | |
int sum = 0; | |
for(Integer i:r) | |
sum += i; | |
if(counter != 0){ | |
r.clear(); | |
socks(sum, b); | |
} | |
return x; | |
} | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int a = z.nextInt(); | |
int b = z.nextInt(); | |
VasyaAndSocks vas = new VasyaAndSocks(); | |
System.out.println(vas.socks(a, b)+a); | |
z.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment