M2#TICE#–#Epreuve#sur#logiciels#4##Extraits#«#Python#»#2011#et#2012!
Exo 5 (2011) – Arithmétique en Python (40 min) – 40 min pour avoir le temps de trouver …
!
"#!$%&'(#!)*%(!+!,-(./.#!01!(#012.%$!+!3!4546+7!8#!9:.!1&%(8#!;1(!#<#&;0#!=%$!-8(.2:(#!
#$!/(182.%$=!8%$2.$:#=>!?:2(#&#$2!.0!#=2!1:==.!=%0:2.%$!)#!01!=:.2#!(-8:((#$2#!@!
u0#=#1#et#un+1#=#1+1/un>!
A$!=#!;(%;%=#!)*:2.0.=#(!8#22#!(#012.%$!;%:(!8108:0#(7!#$!#$2.#(=!0%$B=7!4CC!%:!4DC!8E.//(#=!
=.B$./.812./=!):!$%&'(#!)*%(>!
5.a.!F%&&#$8#(!;1(!:$!10B%(.2E&#!%().$1.(#7!=:(!0#=!$%&'(#=!(-#0=7!;%:(!8108:0#(7!G!01!
;(-8.=.%$!=21$)1()!)#!0*%().$12#:(7!01!,10#:(!)#!+!;1(!8#22#!=:.2#!(-8:((#$2#>!F#22#!
;(#&.H(#!;1(2.#!)#,(1.2!,%:=!=#$=.'.0.=#(!1:!8(.2H(#!)*1((I2!)#!01!'%:80#>!!
J$(#B.=2(#(!8#!;(#&.#(!;(%B(1&&#!=%:=!0#!$%&!nbor1.py!
!
Il#s’agit#maintenant#d’adapter#ce#premier#algorithme#à#une#utilisation#sur#des#entiers#longs.##
Le#schéma#général#est#le#même,#et#l’algorithme#ne#fait#que#quelques#lignes.#
!
"#!;(.$8.;#!#=2!9:*1:!0.#:!)#!;1(2.(!)#!:C!3!47!%$!;1(!)#!:C34C;7!;1(!#<#&;0#!1,#8!!
;!34C!K4CLL;!#$!MN2E%$O!;%:(!,%=!;(#&.#(=!#==1.=>!P1$=!8#!81=7!.0!,1!/100%.(!(#&1(9:#(!
9:#!0#=!)#:<!$%&'(#=!4!)#!01!(#012.%$!et#un+1#=#1+1/un!$*%$2!#$!/1.2!;1=!0#!&I&#!=#$=!#2!
$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