URI Online Judge | 1099
Soma de Ímpares Consecutivos II
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1
Leia um valor inteiro N que é a quantidade de casos de teste que vem a seguir. Cada caso de teste consiste de dois inteiros X e Y. Você deve apresentar a soma de todos os ímpares existentes entre X e Y.
Entrada
A primeira linha de entrada é um inteiro N que é a quantidade de casos de teste que vem a seguir. Cada caso de teste consiste em uma linha contendo dois inteiros X e Y.
Saída
Imprima a soma de todos valores ímpares entre X e Y.
URI Online Judge | 1099
Sum of Consecutive Odd Numbers II
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Read an integer N that is the number of test cases. Each test case is a line containing two integer numbers X and Y. Print the sum of all odd values between them, not including X and Y.
Input
The first line of input is an integer N that is the number of test cases that follow. Each test case is a line containing two integer X and Y.
Output
Print the sum of all odd numbers between X and Y.
n = int(input())
d = 0
for c in range(1 , n + 1):
x = input().split()
a, b, = x
s=0
a = int(a)
b = int(b)
if a > b:
for d in range(int(b)+1, int(a)):
if d % 2 != 0:
s = s + d
if a < b:
for d in range(int(a)+1, int(b)):
if d % 2 != 0:
s = s + d
if a == b:
s = 0
print(s)
n = int(input())
d = 0
for c in range(1 , n + 1):
x = input().split()
a, b, = x
s=0
a = int(a)
b = int(b)
if a > b:
for d in range(int(b)+1, int(a)):
if d % 2 != 0:
s = s + d
if a < b:
for d in range(int(a)+1, int(b)):
if d % 2 != 0:
s = s + d
if a == b:
s = 0
print(s)
Nenhum comentário:
Postar um comentário