Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Compute the prime factors of a number using "bc", to run type "bc -q filename"
- A translation of my program in C, this one can handle large numbers.
- (Keep in mind that factoring large numbers may easily become infeasible...)
- Copyright (C) <April 13, 2015> Henning POLZER, h underscore polzer at gmx dot de
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- define primfaktoren (z) {
- scale = 0
- s = z
- faktor = 2
- flag = 0
- exponent = 0
- print z, " = "
- og = sqrt (z) + 1
- og /= 1 /* og abrunden */
- if (z > 3)
- while (faktor < og + 1) {
- if (z % faktor == 0) {
- exponent += 1
- af = faktor
- if (exponent < 2) print faktor
- flag = 1
- z = z / faktor
- z /= 1 /* z abrunden */
- og = z
- } else {
- if (faktor % 2 != 0) faktor += 2 else faktor += 1
- exponent = 0
- }
- if ((z % faktor != 0) && (exponent > 1)) print "^", exponent
- if ((z % faktor == 0) && (faktor != af) && (flag == 1)) print " * "
- }
- if (s == 1) print "1 * 1" else
- if (s == z) print "prim"
- print "\n"
- }
- /* 2^2 * 3^3 * 5^8 * 7^4 * 11^3 * 13^19 * 17^3 * 19^2 * 23^9 =
- 629625327458173519519741453570279519028974075767187500 */
- primfaktoren (629625327458173519519741453570279519028974075767187500)
- quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement