Pages

Sunday 11 November 2012

UVA - 11480 - Jimmy's Balls


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer("");
        String m = "";
        int i=1;
        while (true) {
            long x = Integer.parseInt(br.readLine());
            if(x==0)
                break;
            long temp=3*((x-7)/6)*((x-1)/6);
            if (x % 6 != 0) {
                temp+=(x%6)*((x-1)/6);
            } else {
                temp+=(x-5);
            }
            sb.append("Case ").append(i).append(": ").append(temp).append("\n");
            i++;
        }
        System.out.print(sb);
    }
}

2 comments:

  1. what is the logic behind the code?plz explain

    ReplyDelete
  2. Just after some trying ... there is a formula for combinations for this specific problem for values divided by 6 ... other values we have to just add some more combinations

    ReplyDelete