Page 1 of 1

Problem 134

Posted: Sat Dec 13, 2008 8:25 am
by Bhilal
for the i < 100 i found these answers
5 7 35
7 11 77
11 13 611
13 17 1513
17 19 817
19 23 1219
23 29 2523
29 31 1829
31 37 2331
37 41 2337
41 43 3741
43 47 3243
47 53 5247
53 59 3953
59 61 1159
61 67 5561
67 71 5467
71 73 1971
73 79 6873
79 83 1079
83 89 4183
89 97 3589
sum 59358

when i generalize it i found an answer which seem incorrect. Can you give me any " sum " up to the any i?
for example what is the sum 5 <= i <= 1000 and 40000 <= i <= 92000 and other. Because it will help to find the correct answer.
Thanks in advance

Re: pe 134

Posted: Sat Dec 13, 2008 10:23 pm
by hk
sum 5<=i<=100 is 69155

Re: pe 134

Posted: Sun Dec 14, 2008 12:07 am
by Bhilal

Code: Select all

 public static long primevu(int i, int j)
    {
        String s = Integer.toString(i);
        
        for(long k=2; k<10000000L; k++)
        {
            long a = j*k;
            
            if(Long.toString(a).endsWith(s))
                return a;
        }
        
        return 0;
    }
I write such a code to find the smallest n. Can you help me to find my mistake?

Re: pe 134

Posted: Sun Dec 14, 2008 12:23 am
by daniel.is.fischer
I'm pretty sure it's just a misreading of the problem statement: "for every pair of consecutive primes with 5 ≤ p1 ≤ 1000000", see it?

Re: pe 134

Posted: Sun Dec 14, 2008 12:37 am
by Bhilal
unfortunately no :) what i understand is finding small n for every consecutive primes (5, 7) n1, (7,11) n2, ... and adding them up.

Re: pe 134

Posted: Sun Dec 14, 2008 1:01 am
by Tommy137
Bhilal wrote:unfortunately no :) what i understand is finding small n for every consecutive primes (5, 7) n1, (7,11) n2, ... and adding them up.
Right... and 5 ≤ p1 ≤ 1000000 as daniel said. There you're overlooking something ;)

Re: pe 134

Posted: Sun Dec 14, 2008 1:14 am
by Bhilal
If so what is the mistake for the 5<=i<=100 sum = 59358? Now 3.09 night in my country :) i try to find the answer then do my programming homework then sleep :D Please help me to correct my mistake

Re: pe 134

Posted: Sun Dec 14, 2008 1:19 am
by daniel.is.fischer
Look at the difference of your result and the one hk gave. That might show you what you've been missing.

Re: pe 134

Posted: Sun Dec 14, 2008 1:23 am
by Bhilal
I looked it it is 9797. i found my mistake. Now i rearrenged my code

Re: pe 134

Posted: Sun Dec 14, 2008 1:27 am
by Bhilal
i found. thanks my friend :D . Now i am starting to fight with tree and file algorithms :) to sunrise

Re: Problem 134

Posted: Tue Mar 06, 2012 7:26 pm
by olleicua
I'm confused by the problem statement. It says "Consider the consecutive primes p1 = 19 and p2 = 23. It can be verified that 1219 is the smallest number such that the last digits are formed by p1 whilst also being divisible by p2."

Isn't 35 a counterexample. 5 and 7 are consecutive primes and and 35 ends in 5 and is divisible by 7. What am I missing here?

Re: Problem 134

Posted: Tue Mar 06, 2012 7:57 pm
by TripleM
1219 is the smallest number that ends in 19 and is divisible by 23. 35 is the smallest number that ends in 5 and is divisible by 7. There's no contradiction there.

Re: Problem 134

Posted: Thu Aug 09, 2012 4:22 pm
by Mathmannix
Are these results correct?
for p in [5,100], sum(S) = 9,797
for p in [5,1E3], sum(S) = 36,941,222
for p in [5,1E4], sum(S) = 27,951,351,491
for p in [5,1E5], sum(S) = 22,415,801,611,632
???
I ask because (a) my program is taking more than 20 minutes to find the sum for p in [5,1E6],
and (b) because it seems that the answer will be a 17-digit number (or so), which seems unlikely for us to have to input in the answer box.

Re: Problem 134

Posted: Thu Aug 09, 2012 8:00 pm
by hk
If your program would take 20 minutes you could either
1)let it run and use the PE answer checker to verify your result
2)try to make a faster one.

Moreover, why should a 17 (or so) digit answer be unlikely?

Re: Problem 134

Posted: Sat Aug 11, 2012 12:44 am
by thundre
I think all of those numbers are correct except the first. I don't know how your algorithm can be right for 1000 but wrong for 100.

Most PE answers fit in a 64-bit signed integer, which can have up to 19 digits, or a 64-bit floating point, in which case the problem states how many digits after the decimal to round to.

Re: Problem 134

Posted: Sat Aug 11, 2012 9:29 am
by hk
thundre wrote:
Most PE answers fit in a 64-bit signed integer, which can have up to 19 digits, or a 64-bit floating point, in which case the problem states how many digits after the decimal to round to.
The PE team don't consider themselves restricted to what you write down here wrt the answer format.
I think you're mixing up computational restrictions with answer format restrictions.

Re: Problem 134

Posted: Sun Aug 12, 2012 5:42 pm
by thundre
hk wrote:The PE team don't consider themselves restricted to what you write down here wrt the answer format.
I think you're mixing up computational restrictions with answer format restrictions.
Of course there are answer formats I didn't even mention. IIRC, at least one problem requires a fraction with a slash between the numerator and denominator. And I realize the "rules" that the team applies to computation algorithms don't necessarily apply to final answers.

I'm just saying that simply having 17 digits is not a reason to doubt an answer. But having 20 digits might be. And if the problem specifies 10 digits to the right of the decimal, but my answer is greater than 106, that value exceeds the 53-bit precision of the double mantissa, which would also be a red flag indicating I'm probably wrong.

Re: Problem 134

Posted: Tue Nov 27, 2012 4:04 pm
by iarribas
I tray again and again but unsuccessfully. My code works for p in 5-10^5 (it coincides with the results given by Mathmannix (Thu Aug 09, 2012 4:22 pm), but when I tray for p in 5-10^6 it fails.

I’ll appreciate any help or suggestion. Any clue I could be forgetting.