Created
January 4, 2016 02:28
-
-
Save HajimeKawahara/f6a9c11cea0d85be6d04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### compute the minimum value 2^p 3^q 5^r (p>=1, q>=0, r>=0 )that exceeds base. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 107, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"next235 (generic function with 2 methods)" | |
] | |
}, | |
"execution_count": 107, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function next235(base,limit=10^12)\n", | |
" #limit : maximum value for search\n", | |
" if rem(base,2)==0\n", | |
" nextv=base\n", | |
" else\n", | |
" nextv=base+1\n", | |
" end\n", | |
" p=0\n", | |
" q=0\n", | |
" r=0\n", | |
" while true\n", | |
" val=nextv\n", | |
" while true\n", | |
" if rem(round(Int,val),2) != 0 break end\n", | |
" p +=1 \n", | |
" val=round(Int,val/2) \n", | |
" end\n", | |
" #println(val,\" p:\",p)\n", | |
" while true\n", | |
" if rem(round(Int,val),3) != 0 break end\n", | |
" q +=1 \n", | |
" val=round(Int,val/3) \n", | |
" end \n", | |
" #println(val,\" q:\",q)\n", | |
" while true\n", | |
" if rem(round(Int,val),5) != 0 break end\n", | |
" r +=1 \n", | |
" val=round(Int,val/5) \n", | |
" end \n", | |
" #println(val,\" r:\",r)\n", | |
"\n", | |
" if val == 1 break end\n", | |
" nextv += 2\n", | |
" p=0\n", | |
" q=0\n", | |
" r=0\n", | |
" if nextv > limit \n", | |
" println(\"Exceed Maximum value=\", limit)\n", | |
" nextv=0\n", | |
" break \n", | |
" end \n", | |
" end\n", | |
" return nextv, p, q, r\n", | |
"end\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 108, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(895795200000,17,7,5)" | |
] | |
}, | |
"execution_count": 108, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"next235(894031679088)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.4.2", | |
"language": "julia", | |
"name": "julia-0.4" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.4.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment