Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

CHFJB – Editorial

$
0
0

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.


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>