Author |
Topic |
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-07-16 : 11:14:08
|
Solve anyway you would like (I would enjoy seeing a SQL version though):On the topic of primes -p(1) = 1p(2) = 2p(3) = 3p(4) = 5p(9594) = ???Good Luck!!Corey |
|
jhermiz
3564 Posts |
Posted - 2004-07-16 : 11:19:48
|
Looking for the 9594th prime ?Jonwww.web-impulse.com |
 |
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-07-16 : 11:20:55
|
Yep. Well, I'm not... you are !Corey |
 |
|
jhermiz
3564 Posts |
Posted - 2004-07-16 : 11:24:12
|
p(n) = 1 + (sum from j=3 to n) ( (j-2)! - j[(j-2)!/j] )Do you want a C++ solution ?Wait till I get home :)...I love this type of stuff :)Jonwww.web-impulse.com |
 |
|
jhermiz
3564 Posts |
Posted - 2004-07-16 : 11:25:23
|
O btw didnt Seive have an algorithm for this?Will research thoughJonwww.web-impulse.com |
 |
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-07-16 : 11:30:02
|
Whats Seive??btw - I'm a math major at clemson, so I also love this stuff Corey |
 |
|
jhermiz
3564 Posts |
|
jhermiz
3564 Posts |
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-07-18 : 01:04:06
|
I have a problem for you. It was a high school problem I had. Never found a real formula for it.What is a 1 digit number where the numbers before it add up to the same thing as some number of numbers after it?6 is the answer because 1+2+3+4+5 = 7+8 (15)What is a 2 digit number? A 3 digit number?Is there a formula to find these numbers or is the only way to find out to test every sumation of number sequences and see? (I know there is a formula for sums of sequences but is there a way to quickly identify these kinds of numbers.) Can you generate the first 15 numbers that have this property?--KenYour Kung-Fu is not strong. -- 'The Core' |
 |
|
jhermiz
3564 Posts |
Posted - 2004-07-18 : 02:29:11
|
quote: Originally posted by kselvia I have a problem for you. It was a high school problem I had. Never found a real formula for it.What is a 1 digit number where the numbers before it add up to the same thing as some number of numbers after it?6 is the answer because 1+2+3+4+5 = 7+8 (15)What is a 2 digit number? A 3 digit number?Is there a formula to find these numbers or is the only way to find out to test every sumation of number sequences and see? (I know there is a formula for sums of sequences but is there a way to quickly identify these kinds of numbers.) Can you generate the first 15 numbers that have this property?--KenYour Kung-Fu is not strong. -- 'The Core'
Hey Ken,You cannot generalize something like this. You're just running into special cases such as 15=7+8. In fact there is too many inconsistances (5 digits on left, 2 on right to total 15, not good) to generalize this or prove it.At least from my understanding I don't think I can generalize this.Maybe you can / cannot but I don't see it.Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
Kristen
Test
22859 Posts |
Posted - 2004-07-18 : 03:27:39
|
Ah, so I CAN use a tally table for this one? <g> but I only get the first 5 as my tally table only goes up to 8,000 :-(SELECT [Total before] = (S1.Number*(S1.Number+1))/2, [Number] = S1.Number+1, [Limit] = S1.Number+S2.Number+1FROM Tally S1, Tally S2WHERE (S1.Number*(S1.Number+1))/2 = (S1.Number+1)*S2.Number+((S2.Number*(S2.Number+1))/2) AND S2.Number <= S1.Number / 2 -- Prevent it taking forever! AND S1.Number < 1000 -- Prevent it taking forever!ORDER BY S1.Number Kristen |
 |
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-07-18 : 03:39:41
|
Sorry for hijacking your post Corey!Good one Kristen. I was trying to do it myself but I was using a correlated subquery and couldn't figure it out. I wrote a BASIC program to solve it years ago and it took about a day to solve for a 5 digit number before the sum became larger than a double could hold. Interestingly, there was only 1 solution for each digit count.--KenYour Kung-Fu is not strong. -- 'The Core' |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2004-07-18 : 04:30:03
|
[code]SELECT x, nFROM ( SELECT n, CAST(FLOOR(SQRT(x2)) AS bigint) AS x, x2 FROM ( SELECT n, (CAST(n AS bigint)*n+n)/2 AS x2 FROM Numbers WHERE n > 0 ) AS A ) AS AWHERE x*x = x2ORDER BY x[/code]BTW, This link might be of interesthttp://www.research.att.com/projects/OEIS?Anum=A001109 |
 |
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-07-18 : 04:51:24
|
I look at that and suppose you wrote it out just as it is, and well, that's just scary.--KenYour Kung-Fu is not strong. -- 'The Core' |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2004-07-18 : 05:16:09
|
Well, a few back of envelope scribblings, and an attack of conscience on the floating point accuracy...But it's still a damned slow way: it turns out that there's a recurrence to calculate square triangular numbers!Not very set-based, I'm afraid:DECLARE @STn2 AS bigint, @STn1 AS bigint, @STn AS bigintSET @STn2 = 0SET @STn1 = 1DECLARE @i AS intSET @i = 0WHILE @i < 12 BEGIN SET @i = @i + 1 SET @STn = 34*@STn1 - @STn2 + 2 PRINT @STn SET @STn2 = @STn1 SET @STn1 = @STnEND Oh, better yet, there's a recurrence for the square root of that too:DECLARE @a3 AS bigint, @a2 AS bigint, @a1 AS bigint, @a AS bigintSET @a3 = 0SET @a2 = 1SET @a1 = 6DECLARE @i AS intSET @i = 0WHILE @i < 23 BEGIN SET @i = @i + 1 SET @a = 7*(@a1 - @a2) + @a3 PRINT @a SET @a3 = @a2 SET @a2 = @a1 SET @a1 = @aEND Much prettier in Haskell: lovely lazy evaluation (ideal for a lazy Sunday), infinite lists and proper bigints:-- Square Triangular numbersst = 0:1:(zipWith (\a b -> 34*a-b+2) (drop 1 st) st)-- Their square roots (i.e. index in square numbers)sts = 0:1:6:(zipWith3 (\a b c -> 7*(a-b)+c) (drop 2 sts) (drop 1 sts) sts)-- index in triangular numbersstt = 0:1:8:(zipWith3 (\a b c -> 7*(a-b)+c) (drop 2 stt) (drop 1 stt) stt)-- put them all together:stall = zip3 sts stt st-- take the 10000th valuest10000 = stall !! 10000 |
 |
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-07-18 : 21:25:24
|
Sorry I disappeared, but I'm glad someone brought more fun to the table (thanx Ken!). I will have to try and decipher arnold's code... I will see if I can come up with a good puzzler...Corey |
 |
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-26 : 12:58:11
|
quote: p(9594) = ???
I make it 100003  --calculationselect max(i) from ( select top 9594 i from ( select i from dbo.F_TABLE_PRIME(110000) union select 1) a order by i) b F_TABLE_PRIME is here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69646Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2006-07-26 : 13:24:33
|
Yes, but what's the 10000th square triangular number? |
 |
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-26 : 14:21:56
|
--calculationdeclare @k intset @k = 10000select power((power(1 + sqrt(2.0), 2 * @k) - power(1 - sqrt(2.0), 2 * @k)), 2) / 32/*result1.53298e+15143*/ Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2006-07-27 : 07:57:16
|
quote: Originally posted by RyanRandall1.53298e+15143
Strange, I make it3328614772044749769841850291665893329510689980001055334718759420358793636509627101982981756485007028041372678953700098486789857119482681149803651860170390906242523786502692535952414473668241662439677067638694950496824738047575451097966736977670149604129782787373211491699749706919113972383789023981951840682815340020558899238769195796271154799086566199043571056789668140208615893554458501430470861953931328031386676564843584881586398731872874525025292789860068606831555141029063669913578841990517963895788186896601623506133188068472523256716890621238883947393675996888276600940616204520108102791672921762617588996731631519643512394782135497156211418392879216621321319885139271589235561151024080569023178335955344221186511936374050275203640003289527842835401233657091518371434289265434784479530983055609636551652873795115915240506576284976312294566415707014154750204400276167211602638822812836160547247121877431965156802527381090319607347965078386075689059367685555694064353398722210150553540574679541283045460395412474766300850956872384229334949815673307933308151803374243909635345975934762443342337976784883108877469814811738240115645085353111532186613512615683546520270495885336540245178585937691761416256365316765930816792753169902092521654473423916464661289952001301663927854253261296407254745066924274604326770826445992236879889317634239290332014728187098758167105754268562063294115477720273989818070736642579400045245054765587185627204909072833719515355924090893418965522419242162210439461995801671531897056196880431283897905090455866575999086758896533376119532674500588269631496596097191818808337239757568732169094342508759369476260373768644723401656085645617416093842641192262108137975674670581441088589047404776734500385146591437280660948682273016687865864019043491892854237717297870642399101275831373540962338980723273435677407295261111833949733212773517548112256410049475770010718508649700886891780446970197835108847610377243834401257140199868584683640619324568442810426067050239983030466615329385984518504776880579641595478051785601394902206242835239170425856171591888578749820713774652667790507624138788683221688671588557903014268534274873333427249054184017557143947863776693999232697049837910593034016237223500802343178552389553991483392769238259163711172617306442333931684316763186347085603534403266516259990407850023234251978304073696201176472686960181194226484991771206083319505621497192893898685921344187647849652410665792532090798166674902489355048846900328260732418927644507288064208043935071937195695668589912614956536738501543773785977487557112704437518151361705053866437362823679598980120575509188108076955230185476158352970184455724864995205462152626409964984152368816549002700952546275781726078529848596680202687943217804252221765007692470132431343190422805355988979107459890643404417327600206723972468864087234535342237308495223656605243250715208171294907446085189002997666970009639191281144292851654405852632769591618212664104914534048929670377938241376437179335791985969838835238824580003498905244593099029298095559329775089999628426350786213618477231820179504108177124258253842060626928340901967362711145897615301043385164553051472306318180440883478037511128148393330068340437525432232355598641727278414110217255477021424390124348569028084396074252465497241878285654176980591707165060700568766220608554971230525142366946686162041052585712318838994016087928173105879737611603383803316440717104407328297623917098309958669722266335460942418791272800023511611055663994642489996068344758258624981484501795238240673199071035828217743962925764569075260134602314332115880631027687134163873748846974480799356177797115706220269151676289032866611683031835367570818020422762103982799657910146854831421739524894579401519778314006592883924509408876165054491115866630015609921545924616710741137676571347418831825308756157568967004864637989945468030119121302209141197351545128080428802519140923787118052146091291110395400773485101298969059060336394593549479163167078116293242739303540347708423538383323642039285350509865651023654895958119280142949040078575107725425293762849456380221560300290913083081044463846439211085417179323341521818234394695414286879994536330027476015067440747612930384968696614390086042003137553328024787935998485085038223514323993155125109475622837395501098205305860489793594437477924202594330325613518333760595768475930524360157041467047044071496989018284972338766408187426404213948611049119187745491884121294882785607330037077918838847192604387000821606748283042082513554661319959430593991743333991932004678441316500065533254127624335076669049177952992999495922267745547647000862608789176582555745237125950981654537719671705147701295041787057836025823168845531661266351192077979794299591385520658067189117446532012678050683139195453208150462810508183081430231318392385774106185693720264470503512331672854122182571601168253584934209756687516100030541538848352040506399413974651614739933966519480809184503638522872068599798119921670097956644159359017388539166338038921679079598164177161177378153224432125919291127394543753521055271851804349659233158849757885779882168607509040604537417967545225345254296006815814864794687822207480711625067856543641289889232841420283601771086240063922454342920915577639843887171721261718601189941451358263214542355477866248111979335115235030080015108487782462895047975591046337633009213364423421509632088524789355576051528189450652470844121018062986307461102534937701595336477413176031489822102848542927914972632219237928476236175439778029861215114950648204008823344410914593747253637730655860794007103024864033129299841497876699850449313728448863170265610988040423506103056300629790541996786664676658305586713377121112477464445862281543665836579554229806250713288086380209684798241762181080889483828854467903891186356735388788609728829550223814210125363048034944313956433227933456818513172991437767854981255174449378076952456429104848609385345297780207078361799751493770076296088363184868851614809478121190686294398371631484945109556180814137844201895944478607005179372037564635251270962147067729108385719036225613289537048228631564645127725843427814615384475239995503010872841925287760989322465972980839028600961692812821712142973056863927452858595852413827983717077631262831206228842446186737793854670024442469051410806098081931982511848477484107807894012683561657199848207438536377265458172204031745764119917732510710906832624189359803291774328933245137864475381362502197007843530256545189269440344021086686073775703815114032947352696828567932483884409824760180568474513945527489322261519971000986892257984119917504542924492737363618549859509611643949602438318230016774529852711302608458807257475907786113928847114119660554145234160846622019642671348764693109494127085299621577151531843163646945874698644696667740154858721294641156430972740543885697801093910712060206994643659462270112406615731213598512709997242971582583809957220123780394800462983485934547050030490100844017377831355168438323110932337540914795142683369571026801777564162910041934065532086065317531346885033749375931638293868347545554308902624902812395026556254094549243991825132129898555543364244015398831946194013869623820333828138522545012059009522372830818478297427277818322164405346931292699959146607025372050928369590713641255930974394711571708623088273898164200172448119416823109591664157068383181428492594426659038460650704055366072252958212029395532496105909492287940953221080478185386264607440227396155394353522568326431635959126066688316035346287549291444925512110422242277927937777541531891897560018336461612441350676538933453908083426416352378406410753468875111171016903262744100999667064281549880098556027273572295605046117021654531046126396163111559845365652609541173866275871852244775062040125469269191348432773467856279707427285693968873873996550266289537794465338723344356295765247522192117748131303511298527208194085798935988214853742734446845406636136653856906348857058873192470144235356663853275415838845607374814108803101599345835169650597595218556626462516968871757441873513429949194294783023272410749230020652709561778550321393180969426074005832208817154010033452347380429471966913343946938220557077590119760382788582246682924626216310516709399164891797725359679857389560441691810199068163456673994665465153564303393304685133522085547645244405057115088151832746914093482155912612180557429145662930070386390272956026368650590971769304823358844593545152157698948485299637180063212422475757792480073390344722588091097310842872203328368199948254704292312591874738565002227415524004719749041185695437888427897709425763725303419353479441084608283264880311788294253990537344189806130114830737824538353414234163425623468368740598011375542071752257454082830676123132874490687040208437870635924042045129285478451757719717151809243088345806428777165432418150326629830754403331407754409164627801230578358353075451404980189959592055797205388250535407435101555890653386765944504028674832915104387597648992493287653910005154902610342653813404982064248117967260936720930754168983139780168914155084057223149937484139121698007937811215677829481111839672217826468317408682432915165702334330261028172617354854234347990351494893861290478536451506862792794448269501595041453504183658881131321218551670602832756218714701715782350238463137083098301865113928055994926855071188243719192677954139527882561894268886791418316454354301553046698944707378379852353598042339695971680684634958424422722368880695385847310548543604696655801765853449334459882798931848002811848619350658264629587292807561964068947240426005866116476623361317797046034586249363715598844675663779340949532592998264767172807750207260512555863579901837474276161610604403820018973939274054686933600996028404134495818450992716576144449918970781772843716327750474388850199841516238580582701424375926642648262617231733197248584132550016832208766549723970702366124017316220754671653819230198093183079797244971346622626797874833096041918948616363635454841676074117604923939786757744278264824085819571240582095609434201601724143240109039955711809473260385365988363092916440979837590645586013043409198323131515884877628919333407209138354840673669318012500871545371096522702413993961384477305619458528843890562418246864799982042374752392077696063495026900816008270890669466484618635283193961110086982008402716245510611182026048237395830486259830302311080958142574921135571694971947587854206531251810769190866097159927948814950638760610158965750686706027336779427459082797198725970184336886476889420258296952567942857327610333427329139964257041100490136348734591674739251493530961370577079324747266943375198635141607870587996842763378674612874990519001299702915093565705481412164022790891387283635531873015350352113242011472277632084158561392311109962429533648952428087024577713767295966759850244455360888999473872736723746497540042899205928634257475634745101061724646682968034909310477443839917540250217245295726613951226777306769715472216616384663657249895820936211816815219548607212182078569196449506211730432804965086131556418452435786505582062208936628010319538922696666617173269548008271538911250942021518187433954646715334200937358578858637910300760244697728770762614374954079967194803469578684674670213375948854299459397442036572205399107107575992767828775032987312420163286531133240862682618749026070017275518422280568683865796697576414643406186464357327165202048162417260109937711458142962653133090690928309652225473019682932528844085163852992285650155576201295798020264648807797324347674291920317613648506961022944816630123084875634285828507752188102861627549178641288925395075704927627353435476421629556306775465212699428797495621256517694541577703580597065376439186676344731484111496735043052000592186975381392223315774164281774982981998598207280208807483368164604565146647268365242263556374476297963807123886549861817526467347145389517601072298245851005887108310410832151090014404811796213338602244375988900081689719092217791769319985314039029806234642069116616366955562735479094857200821800956801517656668786488734579823590696121312881938374002982095415085941675198279619767090263042035249513969426913224946048153187097523823291300056329238546482176573542693657791454768583871580753924455105656178944533602046765721782929833903962449597757886712049241628926569382530875061117303964774082647095617364448596619814155505687470012471767401448123828572900974508247375697414775315048385494541551142295301453182889692659764122697660806675261360701189688688935650857159925545196294258715387165114311187715700033235442908406502141970589861437374432397980105196190205490640918304840476581186738902033881506642922044576232657341613417938198674312541086386898012602780988285136469306297318745770142165470274776925117636174552257968370096547458467527972981126544363149925448178551073054040085832271088192207233876999240584465583311807592900417785671367967698247192055663965260556349559755318133843345488374552216986427908874571464270419815080999728563135105249142034254977877495981522955271028256311295862283319575593275312919005138586384456101740543290337936078427231189490954278662920819738593202019499165963202988662697728708116299507776909282947231729349445087419240392329862928703323554440456906751348022175633056807606354220817105374749786936204921298219646146253222448538721873577848158462697052217659871324100556609870510221640577271499919360143702582515895902938555924275053596636256902000860839317606463107358154357931535578393417913285320016531036088523717522087950169471587996048686013217393455180303705695481755529313528467847750589119947422907491829246984230328266375482268943800932356757639293162400683749056970802566549488698016197667769129476946401802569937635146217838245848111432678141969142231235517426567652033830680926734399821957903033411898865700203039427821875677628044769990736549568285327565059262452623273440989522812914250378345010321176522748634605299987557775032508513382660251011949331354533105800084416785446812041023891362173253230882299682600894729199905179194664326880392910733242760165383293902855494345534205866406921637660848324742269557936443029299011177571328759465813622113206075729576304231589165804549002428698129285602443294201380289871101692001941019784808941910836872153214353993808556904421566063389248941667657184708548248454817486513540326605126371021063814661344047750403747938734564951719913541909333712032726650770471736428133214636268932364424190778390032819657698012688590768340057358841105295762899734873873281505785251187213717225774047320306148075319290562638649588425992590993912633865906916986539132705996207104822024438978588291873675658365671340903030349667418379141381197292080301589760264519324969761852677226975747797545162769411020713257827191251472169797848888810482503805504890447531768220255898629270511653353246616025926558713632838085687360725776678334662466771322168140588325926201841194042943959231322078277553843600339798704195163437881189273561357006977416387209878956960107786346594655853042888646443929722994289438442173275580106189263288355717356805096299176049608526348901300793357645130964687650713734344158309076314962786089026797260240988634864077497999855055831432647393404078439558628287179663674161317989545552936727448724901321034129364285541479341267957672921126938308748592928688800007805084202284469705014730954221493258496 |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-07-27 : 08:57:54
|
It makes be feel so inadequate when you quote those things from memory Arnold |
 |
|
Next Page
|