You are Here: Home >< Maths

# A Little Maths Challenge watch

1. Those look like ten consecutive digits from e that add up to 49...

If I'm correct, f(5) should be: **********.

Edit:
Heh, I was correct. I edited out the number I got, just in case I don't ruin someone else's fun.

And to prove I did get it right: f(6) = 2952605956.
2. yes yes well done you turnip - now go get a job at google :P
3. My programming skills let me down
4. (Original post by Willa)
yes yes well done you turnip - now go get a job at google :P
If only they'd hire a 16 year old...
5. Okay... I have a question. Obviously, if you want to solve the first puzzle, you have to check if the 10 digit number (\$n) you obtained is divisible by \$i (where 3<=\$i<=sqrt(\$n)).

I realise the easiest way to check this is using the modulus sign (%), and checking if the remainder is 0, i.e. if \$n % \$i = 0. If it is, then the number isn't prime.

But when I tried this method, I ended up with a lot of numbers (including the one needed). So I took another approach: I used regex to match . (the decimal dot), and if for any division that dot wasn't there, the number wouldn't be prime.

The second method worked perfectly. So my question is: how come the first one didn't?

Here's my function:

PHP Code:
``` function checkprime(\$n) {     \$l = substr(\$n,-1);     if ((\$l != 1) && (\$l != 3) && (\$l != 7) && (\$l != 9)) { return 0; }     \$x = floor(sqrt(\$n));     for (\$i=3;\$i<=\$x;\$i++) {         if (!preg_match("/\./",(\$n/\$i))) { return 0; }         /*The above is the line in question...          Why won't (!(\$n%\$i)) or ((\$n%\$i) == 0) work?*/     }     return 1; }  ```
6. got to be something to do with the way the % operator works. I cant think what else.

What numbers did the % method return? (list a few of them in order which they were found from the e number series)

I'm assuming that the multiple answers given by % appeared BEFORE the actual answer. If the answer was the first returned value, well then there is no problem.
7. Here are the results I got using the % method:

8281828459
2845904523
4590452353
5235360287
3536028747
5360287471
3602874713
7135266249
3526624977
2662497757
2497757247
9775724709
7757247093
5724709369
7247093699
2470936999
7093699959
9369995957
6999595749
9595749669
9574966967
4966967627
9669676277
6762772407
2772407663
7240766303
4076630353
6630353547
3035354759
5354759457
3547594571
5475945713
5945713821
9457138217
3821785251
8525166427
5166427427
4274274663
2742746639
7427466391
4274663919
2746639193

Btw, I used e=718281828459045235360287471352 66249775724709369995957496696762 77240766303535475945713821785251 6642742746639193.
8. it's not being fussy about the spacing is it..... just try (\$n % \$i) just to be sure.
9. I tried that. I even tried setting \$n % \$i to another variable, but nothing worked.

I think I just found a PHP bug?
10. lol "fantabulous" my butt
11. can you please post the complete php code for me to check. I just did a dummy run using your checkprime function with modulus sign, and it worked fine!
12. PHP Code:
``` \$e = "71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193"; #There aren't supposed to be any spaces in \$e... I don't know why this happens when I post. :P for (\$n=0;\$n<101;\$n++) {     \$p = substr(\$e,\$n,10);     if ((checkprime(\$p)) && (\$p{0} != '0')) { echo "<b>MATCH</b> \$p<br>"; } } function checkprime(\$n) {     \$l = substr(\$n,-1);     if ((\$l != 1) && (\$l != 3) && (\$l != 7) && (\$l != 9)) { return 0; }     \$x = floor(sqrt(\$n));     for (\$i=3;\$i<=\$x;\$i++) {         if (!preg_match("/\./",(\$n/\$i))) { return 0; }     }     return 1; }  ```

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: July 30, 2004
Today on TSR

### Uni league tables

Do they actually matter?

### University open days

• University of Warwick
Sat, 20 Oct '18
• University of Sheffield
Sat, 20 Oct '18
• Edge Hill University
Faculty of Health and Social Care Undergraduate
Sat, 20 Oct '18
Poll
Useful resources

### Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

### How to use LaTex

Writing equations the easy way

### Study habits of A* students

Top tips from students who have already aced their exams