Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-10783
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1724
Code:
import java.util.Scanner;
public class Uva_10783Demo {
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int i=input.nextInt();
for(int k=1;k<=i;k++){
int a=input.nextInt();
int b=input.nextInt();
System.out.printf("Case %d: %d\n", k, OddSum(a, b));
}
}
public static int OddSum(int a,int b){
if (a % 2 == 0)
a++;
if (b % 2 == 0) {
b--;
}
int i = (b - a + 2) / 2;
return i * (a + (a + 2 * (i - 1))) / 2;
}
}
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-10783
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1724
Code:
import java.util.Scanner;
public class Uva_10783Demo {
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int i=input.nextInt();
for(int k=1;k<=i;k++){
int a=input.nextInt();
int b=input.nextInt();
System.out.printf("Case %d: %d\n", k, OddSum(a, b));
}
}
public static int OddSum(int a,int b){
if (a % 2 == 0)
a++;
if (b % 2 == 0) {
b--;
}
int i = (b - a + 2) / 2;
return i * (a + (a + 2 * (i - 1))) / 2;
}
}
No comments:
Post a Comment