0

where X is any positive integer.

As stated in this answer.

1LL is used when bit-shifting beyond int in C++ and used in competitive programming a lot.

What is the best way to do this operation in Python ?

Is it as simple as doing just 1 << X ? or something more complicated than that.

Abhishek
  • 412
  • 5
  • 17

2 Answers2

1

yes it is the same in python. unlike c or java, python's integer doesn't have max size. therefore there is no need in python to make distinction between signed shift and unsigned shift. both are done with << or >>. python doesn't have such weaknesses as integer overflow

example:

i=10**1000
print(i)
print(10 << 5000)
print(-10 << 5000)

output:

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1412467032139426036835209667016147333668896175184541116813688085857118169842707512558089126316711526373356032084313660827642038380699793383359711857266399234310517778518653990118779996451317070693734982126313237525531112153728440359509005359548607334184534055755667368015655874054646996404990508496994723579009056175713766182282164342131815209915566771264986517822041740618309392391768613413832940182402258386927255961470051442432810752756294953390938131989667356336063296910238424541258358886568731339812872409800088380736682218042644329108940307890202194405781984882673397682388722799021574203072475705104238458688725967358918058187277964357530185180866413560128513025467268230092502183280182519073402454498631832656379878621985110463629854619495872811191399072280043859428809539588165545676252960869168857748289344499413624165886753269403325611036645569826222068344742198110818724049295034819913767403798259987914118798027175838854985751152994717434692411170702303981033786152327937102909926564448428955118303557331520208041579200900418119518804567055154683494461827317423276859892776076207095258783187664883683489650154749978641197654414333569280123441117657353363935578792149370043475682086659587177640592935928875142928435570470891648764831166156918862038129975556901718921697337552244690324750787978309013215799401273372106943772834399222802740607982347867404348934581201983411010338125067200466098911607002840021009804529640397887043353026193375978620521922803714811321641471865141690909171919093760
-1412467032139426036835209667016147333668896175184541116813688085857118169842707512558089126316711526373356032084313660827642038380699793383359711857266399234310517778518653990118779996451317070693734982126313237525531112153728440359509005359548607334184534055755667368015655874054646996404990508496994723579009056175713766182282164342131815209915566771264986517822041740618309392391768613413832940182402258386927255961470051442432810752756294953390938131989667356336063296910238424541258358886568731339812872409800088380736682218042644329108940307890202194405781984882673397682388722799021574203072475705104238458688725967358918058187277964357530185180866413560128513025467268230092502183280182519073402454498631832656379878621985110463629854619495872811191399072280043859428809539588165545676252960869168857748289344499413624165886753269403325611036645569826222068344742198110818724049295034819913767403798259987914118798027175838854985751152994717434692411170702303981033786152327937102909926564448428955118303557331520208041579200900418119518804567055154683494461827317423276859892776076207095258783187664883683489650154749978641197654414333569280123441117657353363935578792149370043475682086659587177640592935928875142928435570470891648764831166156918862038129975556901718921697337552244690324750787978309013215799401273372106943772834399222802740607982347867404348934581201983411010338125067200466098911607002840021009804529640397887043353026193375978620521922803714811321641471865141690909171919093760
jeff pentagon
  • 796
  • 3
  • 12
1

It's just 1 << X, since integers in Python are arbitrary-precision.

AKX
  • 152,115
  • 15
  • 115
  • 172