{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"primalité.ipynb","version":"0.3.2","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"metadata":{"id":"276xDlo2KOVp","colab_type":"text"},"cell_type":"markdown","source":["# **Nombres premiers**\n","\n","**Définition:**\n","\n","un nombre premier est un entier naturel qui admet exactement deux diviseurs entiers naturels.\n","\n","##**Partie A test de primalité avec une boucle bornée**\n","\n","1. On considère l'algorithme ci-dessous, traduire cet algorithme en une fonction Python \$estprema(n)\$ qui renvoie True si l'entier \$n\$ est premier et False sinon.\n","\n","\n","---\n"," \n",">>> Fonction \$estprema(n)\$\n"," \n",">>> >Si \$n<2\$\n"," \n",">>>>>renvoyer False\n"," \n",">>>>Si \$n=2\$\n"," \n",">>>>>renvoyer True\n"," \n",">>>>Pour \$i\$ allant de \$2\$ à \$n-1\$\n"," \n",">>> >>Si \$i\$ divise \$n\$\n"," \n",">>> >>>Renvoyer False\n"," \n",">>>>Renvoyer True \n","\n","---\n","\n"]},{"metadata":{"id":"J_STGeCK3oP2","colab_type":"code","colab":{}},"cell_type":"code","source":["# Programme:\n","\n"],"execution_count":0,"outputs":[]},{"metadata":{"id":"B7gJD0-eOaqS","colab_type":"text"},"cell_type":"markdown","source":["2. Modifier la fonction afin qu'elle renvoie également une décomposition de l'entier \$n\$, par exemple \$estprema(10)\$ doit renvoyer \$False,5,2\$.\n","\n","3. Tester la fonction avec un nombre le nombre \$50370952483\$.\n"]},{"metadata":{"id":"tBSH0dlEPV6f","colab_type":"code","outputId":"06585131-0e4b-4790-a93c-73aac67f214d","executionInfo":{"status":"ok","timestamp":1548391957860,"user_tz":-540,"elapsed":657,"user":{"displayName":"Mohamed EL AHMADI","photoUrl":"","userId":"15958821790435656147"}},"colab":{"base_uri":"https://localhost:8080/","height":36}},"cell_type":"code","source":["#Programme\n","\n"],"execution_count":0,"outputs":[{"output_type":"stream","text":["(False, 502669, 100207)\n"],"name":"stdout"}]},{"metadata":{"id":"8CUBm6WKPasj","colab_type":"text"},"cell_type":"markdown","source":["## **Partie B test de primalité avec une boucle non bornée**\n","\n","On considère la fonction Python ci-dessous:\n","\n","\n"]},{"metadata":{"id":"ED-1sjEyQJit","colab_type":"code","colab":{}},"cell_type":"code","source":["def estpremb(n):\n"," if n<2:\n"," return False\n"," if n==2:\n"," return True\n"," d=2\n"," while d*d<=n:\n"," if n%d==0:\n"," return False\n"," d=d+1\n"," return True\n","\n"],"execution_count":0,"outputs":[]},{"metadata":{"colab_type":"text","id":"PeB8aZsVTz2v"},"cell_type":"markdown","source":["1. Expliquer et justifier le choix de la condition à la ligne 7 du programme:\n","\n"]},{"metadata":{"id":"NQh8io1iUFbP","colab_type":"text"},"cell_type":"markdown","source":["Répondre ici:\n","\n","\n","\n","\n","\n"]},{"metadata":{"id":"gjsI70oRQg07","colab_type":"text"},"cell_type":"markdown","source":["2. Quel est le 1001 ème nombre premier?\n"]},{"metadata":{"id":"Hep7c_7PWt5P","colab_type":"code","colab":{}},"cell_type":"code","source":["# Programme\n","\n"," "],"execution_count":0,"outputs":[]},{"metadata":{"id":"S9h3CTYvUNKk","colab_type":"text"},"cell_type":"markdown","source":["Répondre ici:"]},{"metadata":{"id":"jabAfsObRGP5","colab_type":"text"},"cell_type":"markdown","source":["## **Partie C Fonction polynôme**\n","\n","\n","En 1772, Léonard Euler étudie la fonction polynôme \$P\$ qui à un entier \$n\$ associe \$P(n)=n^2+n+41\$.\n","\n","1. Écrire une fonction Python qui prend un entier \$n\$ en paramètre et renvoie l'image de \$n\$ par \$P\$.\n"," \n"]},{"metadata":{"id":"uinSqPqGSwOf","colab_type":"code","colab":{}},"cell_type":"code","source":["# Programme\n","\n"],"execution_count":0,"outputs":[]},{"metadata":{"colab_type":"text","id":"-4eu4csBS5ZP"},"cell_type":"markdown","source":["2. En utilisant la partie B, faire afficher le premier entier \$n\$ dont l'image par \$P\$ n'est pas un nombre premier.\n"]},{"metadata":{"colab_type":"text","id":"esaBUEIRTH3A"},"cell_type":"markdown","source":["3. Modifier votre programme pour qu'il affiche la liste des nombres premiers obtenus avant d'atteindre un nombre composé."]},{"metadata":{"id":"rp8uSyLONedO","colab_type":"text"},"cell_type":"markdown","source":["\n","\n","---\n","\n"]}]}