Pages

Sunday 9 September 2012

UVA - 10783 - Odd Sum


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int cases=s.nextInt();
        for(int i=0;i<cases;i++){
            int a,b;
            a=s.nextInt();
            b=s.nextInt();
            if(a%2==0)
                a++;
            if(b%2==0)
                b--;
            int n=(b-a)/2 +1;
            float x=(float) ((n/2.0)*(a+b));
            System.out.println("Case "+(i+1)+": "+(int) x);
        }
    }
}

No comments:

Post a Comment