Objective In this challenge, we're going to use loops to help us do some simple math. Task Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: N x i = result . Input Format A single integer, . Constraints Output Format Print lines of output; each line (where ) contains the of in the form: N x i = result . Sample Input 2 Sample Output 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20 Explanation: Here, we just need to use for loops to achieve the result Solution : import java.io.* ; import java.math.* ; import java.security.* ; import java.text.* ; import java.util.* ; import java.util.concurrent.* ; import java.util.regex.* ; public class Solution { public static void main ( String [] args ) throws IOException { BufferedReader bufferedReader = new BufferedReader ( new InputStreamReader ( Syste
Problem Description
Question – : Some prime numbers can be expressed as a sum of other consecutive prime numbers.
For example
5 = 2 + 3,
17 = 2 + 3 + 5 + 7,
41 = 2 + 3 + 5 + 7 + 11 + 13.
Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2.
Write code to find out the number of prime numbers that satisfy the above-mentioned property in a given range.
Input Format: First line contains a number N
Output Format: Print the total number of all such prime numbers which are less than or equal to N.
Constraints:
Question – : Some prime numbers can be expressed as a sum of other consecutive prime numbers.
For example
5 = 2 + 3,
17 = 2 + 3 + 5 + 7,
41 = 2 + 3 + 5 + 7 + 11 + 13.
Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2.
Write code to find out the number of prime numbers that satisfy the above-mentioned property in a given range.
Input Format: First line contains a number N
Output Format: Print the total number of all such prime numbers which are less than or equal to N.
Constraints:
2<N<=12,000,000,000
Input
Input
20
Output:
2 (Below 20 there are two such members; 5 and 17) 5=2+3 17=2+3+65+7
Logic:
- Input the number
- Find the prime numbers upto range
- Find the sum of prime numbers consecutively
- And also check If the sum is below the given number
- And also find count
- If the sum is above the given number Break
- print count
Program:
Comments
Post a Comment