Long Long Long int= String ? ? ? ?

What is the result if you multiply the first 100 positive prime number, input only the first 33 digit of the number :v . Hint : the answer doesnt fit in Qword/Unsigned long long int ...


The answer is 471193079990618495316248783476026.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

A Steven Kusuman
Jan 28, 2015
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include<stdio.h>

#include<cstring>

#include<iostream>

#include<cmath>

using namespace std;

void itos(int i,string &s){

char c;
if(i>0){
    c=char(i%10+48);
    s=s+c;
    i=trunc(i/10);
    itos(i,s);

}
}
string tam(string s1,string s2)
{

     string has;
     int p1,p2,i;
     int isi,ban=0;

     p1=s1.size(); p2=s2.size();
     has="";
     if(p1<p2) for(i=0;i<(p2-p1);i++) s1="0"+s1; else
     if(p2<p1) for(i=0;i<(p1-p2);i++) s2="0"+s2;
     p1=s1.size();
     for(i=p1-1;i>=0;i--)
     {

        isi=int(s1[i])-48+int(s2[i])-48+ban;
        ban=isi/10;
        isi%=10;
        has=char(isi+48)+has;

     }
     if(ban>0) has=char(ban+48)+has;

     return has;

}

string kal(string s1,string s2)
{

    string has="0",ban="";
    int ang,sim=0;
    int p1=s1.length(),p2=s2.length();

    if (p2 > p1) return kal(s2,s1);
    for (int i=p2-1;i>=0;i--)
    {

        ban="";sim=0;
        for (int j=p1-1;j>=0;j--)
        {

            ang = sim + (int(s2[i])-48)*(int(s1[j])-48);
            sim = ang / 10;
            ang%= 10;
            ban = char(ang+48) + ban;

        }
        if (sim > 0) ban = char(sim+48) + ban;
        for (int j=0;j<(p2-1-i);j++)
            ban+='0';
        //cout<<ban<<endl;
        has=tam(has,ban);

    }

    return has;

}

int main(){

bool arr[1001];
long int arr2[101];
long int x,cnt=0;
memset(arr,true,sizeof(arr));
for (int i=2;i<=trunc(sqrt(1000));i++){

    if(arr[i]==true){

        x=trunc(pow(i,2));
        while(x<=1000){

            arr[x]=false;
            x=x+i;

        }

    }

}

unsigned long long int row=0;
for (long int i=2;i<=1000;i++){

    if(row>99) break;

    if(arr[i]==true){
       arr2[row]=i;
       row++;

    }

}
string xs,xc,cx;
xs=kal("1","1");
for (long int i=0;i<100;i++){

    xc="";
    cx="";
        itos(arr2[i],xc);
for (int ii=xc.length()-1;ii>-1;ii--){

    cx=cx+xc[ii];
}

     xs=kal(xs,cx);
}

cout<<xs;
return 0;

} 

Long and not understandable.

Hasmik Garyaka - 3 years, 9 months ago
Brock Brown
Feb 1, 2015

Python:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from math import sqrt
def is_prime(x):
    if x < 2:
        return False
    i = 2
    while i <= sqrt(x):
        if x % i == 0:
            return False
        i+=1
    return True
primes = []
guess = 1
product = 1
while len(primes) < 100:
    if is_prime(guess):
        primes.append(guess)
        product *= guess
    guess += 1
print "Answer:", str(product)[0:33]

Evaluation time: 0.01164 seconds

Python is not challenging enough :)

A Steven Kusuman - 6 years, 4 months ago

Log in to reply

It really isn't, the plain English that it offers makes most algorithms almost too easy to construct and understand.

Brock Brown - 6 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...