+ 13
Challenge :: Smallest Number With N Divisors. All language.
Divisor - A number that divides into another without a remainder. I.e. divisors of 40 = 1,2,4,5,8,10,20,40 count = 8 divisors of 24 = 1,2,3,4,6,8,12,24 count = 8. There are a lot of numbers with exact 8 divisors but 24 is smallest. So 24 is smallest number with exact 8 divisors. Create a program So if u enter n = 8 output should be 24. for help https://oeis.org/A005179 Happy Coding
16 Respuestas
+ 12
exactly how you want it, in Python :
https://code.sololearn.com/co1D552NEKqB/?ref=app
+ 34
//not a code , but here is my approach to the question , hope u will like it
👉1)mathematical approach
//when u don't hv code & u asked for answer
any number(obviously natural here) can be expressed as product of prime numbers
ie N= a^x . b^y .c^z ..... & so on //where a,b,c ... are prime
//so number of divisors of N will be n = (x+1). (y+1). (z+1) .... & so on
//example :: 24=2^3 . 3^1 //so no. of divisors of 24 are (4.2) = 8
so when u were provided with n , then divide n between prime no.'s such that u get least value of N
example ::: when n=8 (ie 2×2×2 or 4×2 or 8×1 ) , for getting least value of N , we must focus on lower primes first , so 2^1 . 3^1. 5^1 or 2^3.3^1 or 2^7.3^0
//ie 30 , 24,128 can have total 8 factors
& 24 is the smallest , hence thats the answer
👉2)code approach
//i know java only, so i will talk about what would my approach in java
u got n as input from the user
//now start a loop from N=1 , make method for calculating no. of factors (all factors will be <=N/2) , when no. of factors comes out to be equal to n , come out of the loop & print N as the answer //as we started from 1 , it will be lowest obviously
//☺👍✌ extra information
also when N=xy=a^q . b^w . c^e ... //where a,b,c ... are prime
//then possible ordered pairs of x,y will be (q+1). (w+1). (e+1) ...
example ::: 24 can be expressed as xy in 8 ways //x,y natural number
bcz 24=2^3 . 3^1 //ie 4.2 =8 ways
{(1,24),(24,1),(2,12),(12,2),(3,8), (8,3), (4,6), (6,4)}
//thats simple combiantions u can make urself , there will be (q+1) ways of choosing a , w+1 ways for choosing b & so on //nothing special 😉
+ 7
+ 7
Note that if p has prime factorisation:
p=a^n1*b^n2*...
p has (n1+1)(n2+1)... factors
+ 6
Here's my try in Python
https://code.sololearn.com/cNvRkMaiTCM4/?ref=app
+ 5
@Yash Thatte, You are right.
+ 5
My answer :
https://code.sololearn.com/Wo19AOnu6C4y/?ref=app
+ 4
One liner - and funny use of python generators.
https://code.sololearn.com/cJ7y5CfumVhb/?ref=app
+ 4
Cool challenge! My attempt in Ruby:
https://code.sololearn.com/cg61Tb2e9DA4/?ref=app
+ 4
@Vasudev Sharma
You should make your shared codes PUBLIC.
+ 3
Other version using Pegasus' remark. Work for difficult values for n like 26 (12288) , 31 (n=1073741824), 138 (answer=188743680) or 274 (answer is 261336857795280739939871698507597986398208)
https://code.sololearn.com/cPe5zS6E40uu/?ref=app
+ 3
Oooops... Version was not public. Here it is Other version using Pegasus' remark. Work for difficult values for n like 26 (12288) , 31 (n=1073741824), 138 (answer=188743680) or 274 (answer is 261336857795280739939871698507597986398208)
https://code.sololearn.com/cPe5zS6E40uu/?ref=app
+ 3
https://code.sololearn.com/cCPCToS11woL/?ref=app
+ 2
This is my try, in python:
https://code.sololearn.com/c0UKrQ7Xztq7/?ref=app
- 1
I have this exercise written in c ++. I followed the idea above but got run over time. I don't know what to do with it anymore. help me