[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What's the matter? Afraid I might roll into your interview

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 5

File: IMG_0008.jpg (55KB, 1338x1338px) Image search: [Google]
IMG_0008.jpg
55KB, 1338x1338px
What's the matter? Afraid I might roll into your interview and ask you to sum all primes under 2 million?
>>
File: 1479687784624.jpg (430KB, 1902x1920px) Image search: [Google]
1479687784624.jpg
430KB, 1902x1920px
*fizzbuzzes*
>>
>>59740723
>>
File: 1490982211415.gif (1011KB, 500x500px) Image search: [Google]
1490982211415.gif
1011KB, 500x500px
#include <stdio.h>
#include <math.h>

#define BELOW 2000000

int isaprime (int num);

int main (void) {

int i;
float sum = 0;

for (i = 2; i < BELOW; i++) {

if (isaprime(i) == 1) {
sum = sum + i;
printf ("\n%d\t%.1f", i, sum);
}
}

getch();
return 0;
}

int isaprime (int num) {

int i;

for (i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
return 0;
}
else {
;
}
}

return 1;
}
>>
>>59741064
how do you explain the sqrt(num)
>>
>>59741107
if the root is smaller than i it isn't a prime. this is due to the definition of primes.
>>
File: 1490716010763_1.jpg (93KB, 919x829px) Image search: [Google]
1490716010763_1.jpg
93KB, 919x829px
>>
>>59741064
>for (i = 2; i < BELOW; i++) {
Wrong. Start from 3, increment in 2. Start sum from 2. Which will also speedup
(i = 2; i <= sqrt(num); i++) {
, as you can also start from 3, and increment in 2 to sqrt(n) because you're only testing odds and even numbers won't divide odd.
>>59741126
>if the root is smaller than i it isn't a prime. this is due to the definition of primes.
No, it's because you'd be repeating already found pair factors, e.g. 2*4 = 8, 4*2 = 8, so you should have limited divisors to sqrt(8), as 2, 4 has already been found.
>>
#include <iostream>

using namespace std;

int main()
{
int j , i;
int flag = 0;
int sum = 3;
for(i = 2; i <= 2000000;i++)
{
cout << i << endl;
for(j = 2; j < i; j++)
{
cout << i <<" % " << j << " = " << i % j << endl;
if((i % j) == 0)
{
flag = 0;
break;
}else
{
flag = 1;
continue;
}

}
cout << flag << endl;
if(flag == 1)
{
cout << i << " Is prime\n";
sum = sum + i;
}else if(flag == 0)
{
cout << i << " Is not prime\n";
}else
{
cout << "IDK...\n";
}
}
cout << sum << endl;
}
Thread posts: 9
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.