You are not logged in. Please login at www.codechef.com to post your questions!

×

CHFJB – Editorial

2
1

PROBLEM LINK:

Practice
Contest

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

DIFFICULTY:

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".

asked 07 Aug '18, 13:23

aparup_ghosh's gravatar image

1★aparup_ghosh
514
accept rate: 0%

edited 09 Aug '18, 15:39

admin's gravatar image

0★admin ♦♦
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) vijju123 ♦♦5★

@happypotter0 I will do it soon. :)

link

answered 07 Aug '18, 14:06

aparup_ghosh's gravatar image

1★aparup_ghosh
514
accept rate: 0%

edited 07 Aug '18, 14:07

@aparup_ghosh also provide the link of this editorial in the contest page :)

link

answered 07 Aug '18, 13:37

harrypotter0's gravatar image

4★harrypotter0
318110
accept rate: 1%

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$?

link

answered 07 Aug '18, 19:26

joffan's gravatar image

5★joffan
9488
accept rate: 13%

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<n;i++) { if((n % i)==0) { c=c+1; } } if(c==0) System.out.println("1"); else System.out.println(c);

} }

link

answered 15 Aug '18, 19:29

shahrukh7's gravatar image

0★shahrukh7
1
accept rate: 0%

<html> <body> <script type="text/javascript"> var a=parseInt(prompt("enter a number")); var b=1; while(b<=a) {var c=a%b; if(c==0) {document.write(b+ "
");} b=b+1; } </script> </body> </html>

link

answered 20 Aug '18, 12:36

adityaraj7354's gravatar image

1★adityaraj7354
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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