Beecrowd 1099 – Sum of Consecutive Odd Numbers II solution in C
Question Link
Solution in C
#include <stdio.h>
int main() {
int n,x,y,i,j,sum=0,temp=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&x,&y);
if(x>y){
temp=x;
x=y;
y=temp;
}
if(x%2==0){
x--;
}
x+=2;
for(j=x;j<y;j+=2){
sum=sum+j;
}
printf("%d\n",sum);
sum=0;
}
return 0;
}
Beecrowd 1099 – Sum of Consecutive Odd Numbers II solution in Python
Solution in Python
def main():
n = int(input())
for _ in range(n):
x, y = map(int, input().split())
if x > y:
x, y = y, x
if x % 2 == 0:
x -= 1
x += 2
sum = 0
for j in range(x, y, 2):
sum += j
print(sum)
if __name__ == "__main__":
main()
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don’t think the title of your enticle matches the content lol. Just kidding, mainly because I had some doubts after reading the enticle.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.