lets see how fast you can do it.
java only.
>java only
Fuck off with your homework
Use DYODH algorithm.
please.
>>59533408
No.
If we help you with the easy shit you'll just become another weak programmer whose deadweight forces us to work harder.
Think hard. Read your textbook. Learn to carry your own weight.
>another shitskin appealing to collectivism
*yawn*
Just drop out
Let me teach you how to properly cheat and do shit in the class. I don't care how badly you do; you're failing at algorithms and a CS degree is an algorithms degree. Here's how I'd solve this problem if I wanted to get nowhere.
Step 1, look up what other people have done on stackoverflow. (i.e. look up code for a sieve of eratosthenes in java)
Step 2, copy and paste whatever has the most flexability
Step 3, you're basically done, just add like 3 more variables and set them inside the already-made if-statements.
Step 4, fuck off
>>59533352
there's an active fucking thread about this RIGHT NOW, you could have spent 2 seconds looking at the solutions and rewriting it in java.
But you can't even do that.
DROP OUT RIGHT NOW
>>59533352
Why the fuck would you use recursion to implement Sieve of Eratosthenes?
>>59533352#include <bitset> // compact STL for Sieve, better than vector<bool>!
ll _sieve_size; // ll is defined as: typedef long long ll;
bitset<10000010> bs; // 10^7 should be enough for most cases
vi primes; // compact list of primes in form of vector<int>
void sieve(ll upperbound) { // create list of primes in [0..upperbound]
_sieve_size = upperbound + 1; // add 1 to include upperbound
bs.set(); // set all bits to 1
bs[0] = bs[1] = 0; // except index 0 and 1
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
// cross out multiples of i starting from i * i!
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i); // add this prime to the list of primes
} } // call this method in main method
bool isPrime(ll N) { // a good enough deterministic prime tester
if (N <= _sieve_size) return bs[N]; // O(1) for small primes
for (int i = 0; i < (int)primes.size(); i++)
if (N % primes[i] == 0) return false;
return true; // it takes longer time if N is a large prime!
} // note: only work for N <= (last prime in vi "primes")^2
// inside int main()
sieve(10000000); // can go up to 10^7 (need few seconds)
printf("%d\n", isPrime(2147483647)); // 10-digits prime
printf("%d\n", isPrime(136117223861LL)); // not a prime, 104729*1299709
it's from competitive programming 3
>>59533352
Rajeet, my friend, you should have finished your assignment earlier in the week.
>>59533962
This is the correct answer
>>59533352
>lets see how fast you can do it
>/g/, do my homework
This isn't hard OP. Do your homework, it's good for you. Answer these questions :
What is a prime number?
How would you test in your head if a number is prime?
A tip: use / and \ is 7/2 the same as 7\2?