How to make this program?
Started by
chilli
, Sep 03 2006 12:23 PM
#1
Posted 03 September 2006 - 12:23 PM
#2
Posted 04 September 2006 - 07:12 AM
This for school?
Anyway, in what language?
You should explain yourself better
Anyway, in what language?
You should explain yourself better
#3
Posted 05 September 2006 - 01:50 AM
You really need to add details on ANY program development programs you have, or have experience with...
If none, I would advise you try to Google for it, and theres a posibility that someone has made such a program before, and made it available.
Chris
If none, I would advise you try to Google for it, and theres a posibility that someone has made such a program before, and made it available.
Chris
#4
Posted 05 September 2006 - 01:56 AM
Sorry guys!! Yes. This is for school. The language is C.
#5
Posted 05 September 2006 - 01:50 PM
Really hard! This problem is known to be in NP, though it is not known whether it is NP-complete (computationally infeasible). I discussed NP and NP-completeness before here:I want to know how to make a program that asks the user to enter a number and then displays all its factors.
http://www.geekstogo...howtopic=121232
Wikipedia describes a number of the standard algorithms for factorization.
http://en.wikipedia....r_factorization
None of them is very good though, keep in mind! They will work only for small enough numbers that you can solve the problem largely by brute force. Factoring very large numbers is VERY hard --- in fact, if you could find an efficient way to do it you would break most known cryptographic systems including RSA, which are used to encrypt bank data. So if you solve this problem watch your back and take all your money out of the bank!
Hope this helps.
EDIT: I'll be more specific. If you are just trying to factor small numbers n, the obvious brute-force approach is just to iterate through all integers less than or equal to (n / 2) and test whether they divide evenly into n (i.e. in C test whether (n % i) == 0 for all i <= n/2). All the numbers that match are the divisors. Then you have to sift through those to find the prime factors, if that is what you want (or if you want all the divisors, you have them).
This algorithm will get very slow as n gets even moderately large (like > 1000 or 10000 or I dunno, it depends on your hardware).
Edited by Swandog46, 05 September 2006 - 01:54 PM.
#6
Posted 05 September 2006 - 02:49 PM
would it help if you could somehow tell it to use the tricks like, if the number is even it's divisible by 2, or if the sum of the last two digits is whatever it's divisible by whatever (i forgot them lol) hmm nevermind because if a factor were to be >10 then you'd still have to use the brute force method. although i guess you could use it in specific cases if i<11, but this is probably all irrelevant, just me thinking
#7
Posted 10 September 2006 - 02:24 AM
That's a good idea, TaNkZ101, but may be we should stopwatch it to see if it's all really worth it. For the sake of a shorter code I would stick to the brute force method
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users