Skip to main content

Accenture

Accenture OA-17 2024

Problem Description

You are planning a picnic for a group of friends who love math. To make it interesting, you decided to bring a unique number of items, N. Your task is to find and return an integer value representing the sum of all the prime numbers till N. In case the number of items is 0 or 1, return 0.

Note: Prime numbers are natural numbers that are divisible by only 1 and the number itself.

Input Format:

  • input1: An integer value N

Output Format:

Return an integer value representing the sum of all the prime numbers till N. In case the number of items is 0 or 1, return 0.

Constraints:

  • 0≤N≤10^6 : The integer value representing the upper limit up to which prime numbers need to be summed.

Example

Sample Input:

N = 10

Sample Output:

17

Explanation:
Prime numbers till 10 are: 2, 3, 5, 7. Their sum is 17.