Jump to content
Hertz

[Programare]Numere Prime

Recommended Posts

Posted

Asta e bun Hertz? 49122557320

Unde 'p.txt' e fisierul asta http://www.9876.com/primes50.txt cu ceva modificari. Adica erau cate 2 spatii si le-am inlocuit cu unul. Plus sters chestia aia de la inceput. Nimicuri.

Nici nu cred ca are rost sa postez sursa, dar fie.

Am pornit de la 999.999, deoarece PHP-ul are indicii de la 0. De fapt ca majoritatea limbajelor.

<?php
$a = file_get_contents('p.txt');
$a = explode(' ',$a);
$sum = 0;
for ($i=999999;$i>=999950;$i--)
$sum += $a[$i];
echo $sum;
?>

Era mai aiurea daca trebuiau si generate. Initial ma gandeam la ciurul lui Eratostene. Dar chiar si cu acesta probabil dura destul de mult.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...