• Loading...

Prime Number and Binomial (Problem 5)

Points : 25

Answer : 9222683165156720133

Consider the prime number 5 and all the binomial coefficient of 4.

4C0 = 1
4C1 = 4
4C2 = 6
4C3 = 4
4C4 = 1

None of the above binomial is divisible by 5. 9 is another such value.

Let sum(p) gives the sum of all such unique values n for p that are less than 255 such that none of the binomial nC0, nC1, ..., nCn is divisible by p.

Find ∑sum(p) for all primes p below 100.

Solution

Following relation can be used to solve this problem,

where k is such that t.pk-1 < 255 < t.pk+1-1

Code

  1. #include<iostream>
  2. using namespace std;
  3. #include<vector>
  4. #include<ctime>
  5. #include<cmath>
  6.  
  7. int primes[100],c=1;
  8. void improved_sieve(int N)  
  9. {  
  10.      int M=(N-1)/2;  
  11.      int x=(floor(sqrt(N))-1)/2,i,j;  
  12.      vector<bool> S(M+1,0);
  13.      primes[0]=2;  
  14.      
  15.      for (i=1;i<=x;i++)  
  16.          if (!S[i])  
  17.          {
  18.             primes[c++]=(2*i+1);
  19.             for (j=2*i*(i+1);j<=M;j+=(2*i+1))  
  20.                 S[j]=1;  
  21.          }
  22.      for (;i<=M;i++)
  23.          if (!S[i])
  24.             primes[c++]=(2*i+1);
  25. }
  26.  
  27. long long pow(long long p,long long m)
  28. {
  29.      long long r=1,i;
  30.      for (i=1;i<=m;i++)
  31.          r*=p;
  32.      return r;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.     improved_sieve(100);
  39.     long long i,t,m,p,k,sum=0;
  40.     for (i=0;i<c;i++)
  41.     {
  42.         p=primes[i];
  43.         for (t=1;t<p;t++)
  44.         {
  45.             for (m=0;(t*pow(p,m)-1)<36028797018963968LL;m++)
  46.             {
  47.                 sum+=t*pow(p,m)-1;
  48.             }
  49.         }
  50.     }
  51.     cout<<sum<<endl;
  52. }
#include<iostream>

using namespace std;

#include<vector>

#include<ctime>

#include<cmath>



int primes[100],c=1;

void improved_sieve(int N)   

{   

     int M=(N-1)/2;   

     int x=(floor(sqrt(N))-1)/2,i,j;   

     vector<bool> S(M+1,0); 

     primes[0]=2;  

     

     for (i=1;i<=x;i++)   

         if (!S[i])   

         {

            primes[c++]=(2*i+1);

            for (j=2*i*(i+1);j<=M;j+=(2*i+1))   

                S[j]=1;   

         }

     for (;i<=M;i++)

         if (!S[i])

            primes[c++]=(2*i+1);

}



long long pow(long long p,long long m)

{

     long long r=1,i;

     for (i=1;i<=m;i++)

         r*=p;

     return r;

}





int main()

{

    improved_sieve(100);

    long long i,t,m,p,k,sum=0;

    for (i=0;i<c;i++)

    {

        p=primes[i];

        for (t=1;t<p;t++)

        {

            for (m=0;(t*pow(p,m)-1)<36028797018963968LL;m++)

            {

                sum+=t*pow(p,m)-1;

            }

        }

    }

    cout<<sum<<endl;

}


Submit your solution

You need to be logged in to submit a solution.

discussions


KoenRcount n = 0?
Q:Is n = 0 to be considered? We know n < 2^55, But is n > 0 or n >= 0?
A:No. n>0.

post a question

Loading...

Top Scorers
KoenR 195
DrKorbin 185
Silence 150
A_A_Lunyov 145
cedricl 145
kozima 145
cgy4ever 135
ProjectYoung 130
pankdm 130
dzetkulic 130
Submissions
Problem1
15 pt
You are not logged in
79
submissions

23
correct (29 %)


Problem2
20 pt
You are not logged in
35
submissions

18
correct (51 %)


Problem3
25 pt
You are not logged in
29
submissions

6
correct (20 %)


Problem4
15 pt
You are not logged in
80
submissions

54
correct (67 %)


Problem5
25 pt
You are not logged in
35
submissions

13
correct (37 %)


Problem6
25 pt
You are not logged in
39
submissions

17
correct (43 %)


Problem7
25 pt
You are not logged in
26
submissions

13
correct (50 %)


Problem8
10 pt
You are not logged in
60
submissions

39
correct (65 %)


Problem9
20 pt
You are not logged in
32
submissions

25
correct (78 %)


Problem10
15 pt
You are not logged in
57
submissions

34
correct (59 %)