×

# CHFJB – Editorial

Author: Arkapravo Ghosh
Tester: Aparup Ghosh
Editorialist: Aparup Ghosh

EASY

# PREREQUISITES:

Primality test, factorization

# PROBLEM:

Given a positive integer N, you need to find the number of factors of N except 1 and itself. If N is a prime number then simply output -1.

# QUICK EXPLANATION:

We can find the number of factors of N except 1 and itself by iterating from 2 upto sqrt(N). If the no of factors in zero(0), then output -1(i.e. N is a prime) otherwise output the number of factors.

# EXPLANATION:

According to the given problem we need to find the number of factors of N except 1 and itself, as it is mentioned that the job cannot be performed in 1 day(according to the instructions) or N days(as Chef will leave). So we iterate from 2 to sqrt(N) and keep a count of the number of factors of N. The idea of iterating from 2 to sqrt(N) is simple, you can identify it with a simple observation. For every number (< sqrt(N) ) which is a factor of N, there is another number(> sqrt(N) ) which is a factor of N too. So for every number(< sqrt(N) ), if it is a factor of N, we increase the count by 2. If the factor is equal to sqrt(N) (in case N is perfect square), then we increase the count by 1. After counting the number of factors of N, if the count is equal to 0(i.e. N is prime), we print -1, else we print the number of factors of N. You can find the solutions below.

# AUTHOR'S AND EDITORIALIST'S SOLUTIONS:

Author's solution can be found here.
Editorialist’s solution can be found here.

This question is marked "community wiki".

514
accept rate: 0%

19.8k350498541

Please wikify the editorials especially if your college friends are to upvote them. Gaining karma by official editorials (of contest you hosted) is not allowed by regulations as you get its reward separately.

(08 Aug '18, 00:50)

 2 @happypotter0 I will do it soon. :) answered 07 Aug '18, 14:06 51●4 accept rate: 0%
 0 @aparup_ghosh also provide the link of this editorial in the contest page :) answered 07 Aug '18, 13:37 318●1●10 accept rate: 1%
 0 Will you be re-judging the competition entries (for the ~20 who got WA without AC) excluding the out-of-range test value of $N=1$? answered 07 Aug '18, 19:26 5★joffan 948●8 accept rate: 13%
 0 import java.util.*; class factors { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n,no,c=0; System.out.print("enter the number "); n=sc.nextInt(); for(int i=2;i
 0 answered 20 Aug '18, 12:36 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×94
×83
×23
×18
×8

question asked: 07 Aug '18, 13:23

question was seen: 370 times

last updated: 20 Aug '18, 12:36