« 万豚記(京都錦通り)で排骨担々麺をいただく。ちょうどいい辛さと、しっかり噛み応えのあるお肉で満足。 | トップページ | 「ベイビー・ブローカー」(是枝裕和監督)を観てきた。面白かったというかいろいろ考えさせられた。暗がりでのシーンはかなりジーンときた。カンヌ男優賞のソン・ガンホさんはさすがの演技でしたが、最後どうなったかって私の解釈で合ってる? »

2022年6月24日 (金)

17個連続するハーシャッド数をPythonで計算してみる。

Fermat Libraryでこれを見た。

なるほど。ある数字があって、それを1桁ずつ区切って足したものが、元の数を割り切れるとハーシャッド数というのか。

で20個を超えては連続しないことが証明されているそう(20個はある)。

長く連続しているもの実際に計算してみたいなと思って調べると、英語版のWikipediaにOEISより長いものが紹介されていた。

https://en.wikipedia.org/wiki/Harshad_number

17個連続するのは

4107593985876801556467795907102490773681×10280 − 10

か。Pythonの整数は多倍長なので簡単にできる。割り算だけちょっと気を付ける(/を使うと桁が長すぎると×になるので//と%で)。

簡単に(もっとうまいやり方あると思いますが)こんな感じ。

n0 = 14107593985876801556467795907102490773681*(10**280)-10

def digit(n):
    return len(str(n))

for k in range(0, 17):
    n = n0 + k  
    n1 = n
    d = digit(n)
    m = 0
    for d in range(d,-1,-1):
        x = n1 // 10**d
        n1 -= x * 10**d
        m += x
    print(k+1, n, m, n//m, n % m)

 

結果はこちら。18個目から×になるのは確認ずみ。

Photo_20220623221801

1 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990 2710 52057542383309230835674523642444615401036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369003690036900369 0

2 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999991 2711 52038340043809670071810386968286576074072298045001844337882700110660272962006639616377720398376982663223902618959793434157137587606049428255256362965695315381777941718922906676503135374400590188122464035411287347842124677240870527480634452231648838067133898930284028033935817041682036149022500922168941350055330136481 0


3 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999992 2712 52019151865327439367506622076336617897053834808259587020648967551622418879056047197640117994100294985250737463126843657817109144542772861356932153392330383480825958702064896755162241887905604719764011799410029498525073746312684365781710914454277286135693215339233038348082595870206489675516224188790560471976401179941 0


4 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999993 2713 51999977832203470536187968695549173511540729819388131220051603391079985256173977147069664577957980095834869148544047180243273129377073350534463693328418724659049023221525985993365278289716181349060081091043125691116844821231109472908219683007740508661997788426096572060449686693697014375230372281607077036490969406561 0


5 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994 2714 51980817928801774342180530239876531959030950626381724392041267501842299189388356669123065585851142225497420781134856300663227708179808400884303610906411201179071481208548268238761974944731024318349299926308032424465733235077376565954310980103168754605747973470891672807663964627855563743551952837140751658069270449521 0


6 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995 2715 51961672139509397998039763930395914451863720073664825046040515653775322283609576427255985267034990791896869244935543278084714548802946593001841620626151012891344383057090239410681399631675874769797421731123388581952117863720073664825046040515653775322283609576427255985267034990791896869244935543278084714548802946593 0


7 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996 2716 51942540448736382755772444429685164851550073637702503681885125184094256259204712812960235640648011782032400589101620029455081001472754050073637702503681885125184094256259204712812960235640648011782032400589101620029455081001472754050073637702503681885125184094256259204712812960235640648011782032400589101620029455081 0


8 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997 2717 51923422840915721591710695278257235088998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841001104158998895841 0


9 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998 2718 51904319300503316984796894433783998431497424576894775570272259013980868285504047093451066961000735835172921265636497424576894775570272259013980868285504047093451066961000735835172921265636497424576894775570272259013980868285504047093451066961000735835172921265636497424576894775570272259013980868285504047093451066961 0


10 141075939858768015564677959071024907736809999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 2719 51885229811977938788038969867975324654950349393159249724163295329165134240529606472968002942258183155571901434350864288341301949246046340566384700257447591026112541375505700625229863920559029054799558661272526664214784847370356748804707613093048915042294961382861346083118793674144906215520411916145641780066200809121 0


11 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 200 705379699293840077823389795355124538684050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0


12 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 201 701870347556059778928746065029974665357263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039800995024875621890547263681592039801 0


13 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002 202 698395741875089185963752272628836176914900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009900990099009901 0


14 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003 203 694955368762404017559989946162684274565566502463054187192118226600985221674876847290640394088669950738916256157635467980295566502463054187192118226600985221674876847290640394088669950738916256157635467980295566502463054187192118226600985221674876847290640394088669950738916256157635467980295566502463054187192118226601 0


15 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 204 691548724797882429238617446426592684984362745098039215686274509803921568627450980392156862745098039215686274509803921568627450980392156862745098039215686274509803921568627450980392156862745098039215686274509803921568627450980392156862745098039215686274509803921568627450980392156862745098039215686274509803921568627451 0


16 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005 205 688175316384234222266721751565975159691756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097560975609756097561 0


17 141075939858768015564677959071024907736810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006 206 684834659508582599828533781898179163770922330097087378640776699029126213592233009708737864077669902912621359223300970873786407766990291262135922330097087378640776699029126213592233009708737864077669902912621359223300970873786407766990291262135922330097087378640776699029126213592233009708737864077669902912621359223301 0

« 万豚記(京都錦通り)で排骨担々麺をいただく。ちょうどいい辛さと、しっかり噛み応えのあるお肉で満足。 | トップページ | 「ベイビー・ブローカー」(是枝裕和監督)を観てきた。面白かったというかいろいろ考えさせられた。暗がりでのシーンはかなりジーンときた。カンヌ男優賞のソン・ガンホさんはさすがの演技でしたが、最後どうなったかって私の解釈で合ってる? »

日記・コラム・つぶやき」カテゴリの記事

コメント

コメントを書く

(ウェブ上には掲載しません)

« 万豚記(京都錦通り)で排骨担々麺をいただく。ちょうどいい辛さと、しっかり噛み応えのあるお肉で満足。 | トップページ | 「ベイビー・ブローカー」(是枝裕和監督)を観てきた。面白かったというかいろいろ考えさせられた。暗がりでのシーンはかなりジーンときた。カンヌ男優賞のソン・ガンホさんはさすがの演技でしたが、最後どうなったかって私の解釈で合ってる? »

最近の記事

最近のコメント

2022年8月
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
フォト
無料ブログはココログ