Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Arshiya's First Code

By TarifEzaz · Limits 2s, 512 MB

Arshiya is just three and she already started programming. She has learned how to write loops. Recently, she found a simple problem written in the exercises segment of her programming book. The problem says, “Given a positive integer N, find the number of odd numbers from 1 to N inclusive”. Arshiya thought to herself, “It’s a piece of cake” and wrote down the following code to solve the problem:

#include <stdio.h>

int main() {
     int N;
     int countOdd = 0;

     for (int i = 0; i < N; i++) {
            if ((i+1)%2 == 1) {
     printf("%d\n", countOdd);
     return 0; 

Excited with her achievement, Arshiya came to you and showed her code. Little did Arshiya know that her code is not optimized. In this problem, your task is to solve Arshiya’s problem, efficiently.


The input contains a single positive integer N (1 ≤ N ≤ 2×1017), the value up to which you have to calculate the odd numbers.


Output a single number, the result of the problem.





90% Solution Ratio

Gulam_KibriaEarliest, 5M ago

Gulam_KibriaFastest, 0.0s

Gulam_KibriaLightest, 0 B

mashfiqur404Shortest, 19B


Login to submit

Related Contests

National Girls' Programming Contest 2019 Preliminary Ended at 2019-10-19 12:00:00 +0000 UTC
Replay of National Girls' Programming Contest 2019 Preliminary Ended at 2019-10-21 18:00:00 +0000 UTC