10311 - Goldbach and Euler
Moderator: Board moderators
hi serur,
once i waste a lot of time working bit field in this way... but i couldnt make it working... then for a while i used to remember the way mf described about changing value... then when i read the bit field things well in a language book, i became clear.
if you dont mind, in my humble opinion, it would be much wiser to read the basic works of bit field, then look at what mf tried to tell. Then go ahead and work on simple bit fields...
you can also have a look here ... http://online-judge.uva.es/board/viewtopic.php?t=10418
i dont know well about balanced search trees, but i think 'bit field with sign', here sign means for flagging... not anything other... and chars are signed by default...
once i waste a lot of time working bit field in this way... but i couldnt make it working... then for a while i used to remember the way mf described about changing value... then when i read the bit field things well in a language book, i became clear.
if you dont mind, in my humble opinion, it would be much wiser to read the basic works of bit field, then look at what mf tried to tell. Then go ahead and work on simple bit fields...
you can also have a look here ... http://online-judge.uva.es/board/viewtopic.php?t=10418
i dont know well about balanced search trees, but i think 'bit field with sign', here sign means for flagging... not anything other... and chars are signed by default...
fahim
#include <smile.h>
#include <smile.h>
Code: Select all
struct{
signed char s:1;
}bit_field;
Code: Select all
bit_field sign;
sign.s=1;
Hi fellows!
Thank you smilitude and mamun for sympathy
mamun wrote:
But I'm sure you want memory efficiency
Yes, all I want is memory efficiency
but:
mamun wrote:
Don't you think here bit_field takes just 1 bit of memory but the whole word which maybe 4 bytes
Yes, you are right, and I WANT ONLY 1 BIT MEMORY FOR SIGN AND NO MORE!
Also, I'd like to use int as base instead of char.
Well, UNIX is only 10% assembly and 90% in C! So I'll work hard to understand these low-level stuffs. But a tiny hint is welcome, all the same
Thank you smilitude and mamun for sympathy

mamun wrote:
But I'm sure you want memory efficiency
Yes, all I want is memory efficiency
but:
mamun wrote:
Don't you think here bit_field takes just 1 bit of memory but the whole word which maybe 4 bytes
Yes, you are right, and I WANT ONLY 1 BIT MEMORY FOR SIGN AND NO MORE!
Also, I'd like to use int as base instead of char.
Well, UNIX is only 10% assembly and 90% in C! So I'll work hard to understand these low-level stuffs. But a tiny hint is welcome, all the same

If there is ever a war between men and machines, it is easy to guess who will start it (c) Arthur Clarke
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 01, 2006 12:59 pm
- Location: (Fci-cu) Egypt
- Contact:
please i got many wa.......
This is my even part is it wrong
Please i need some test cases
also what is the output for
This is my even part is it wrong
Code: Select all
if(n % 2 == 0) //So even //Test all possiblities eficiently
{
bool flag = false;
int mid = n / 2; //Any number is divided to 2 sides
if(mid != 2 && mid % 2 == 0)
--mid; //Start from odd and use -=2 Optimization
for(int k = mid; k > 0; k -= 2)//(p2-p1) is positive and minimized
{
if(isprime(k) && isprime(n - k))
{
// if(k < n-k)
possible(n, k, n - k);
// else
// possible(n, n - k, k);
flag = true;
break;
}
}
if(!flag)
cout<<n<<" is not the sum of two primes!"<<"\n";
}
Please i need some test cases
also what is the output for
Code: Select all
1
2
3
4
5
6
7
8
9
10
11
12
Sleep enough after death, it is the time to work.
Mostafa Saad
Mostafa Saad
In my solution I would check if mid is even, and if yes do mid--, if not mid-=2. (without that mid != 2 part)
And my loop would go down to 3 (not to 1).
For that input:
And my loop would go down to 3 (not to 1).
For that input:
Code: Select all
1 is not the sum of two primes!
2 is not the sum of two primes!
3 is not the sum of two primes!
4 is not the sum of two primes!
5 is the sum of 2 and 3.
6 is not the sum of two primes!
7 is the sum of 2 and 5.
8 is the sum of 3 and 5.
9 is the sum of 2 and 7.
10 is the sum of 3 and 7.
11 is not the sum of two primes!
12 is the sum of 5 and 7.
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 01, 2006 12:59 pm
- Location: (Fci-cu) Egypt
- Contact:
THANKS THANKS THANKS THANKS THANKS THANKS
THANKS THANKS THANKS THANKS THANKS THANKS
I got accepted NOWWWWWWWW FINALYYY
http://acm.uva.es/problemset/usersjudge.php?user=8957
THANKS THANKS THANKS THANKS THANKS THANKS
I got accepted NOWWWWWWWW FINALYYY
http://acm.uva.es/problemset/usersjudge.php?user=8957
Sleep enough after death, it is the time to work.
Mostafa Saad
Mostafa Saad
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
why getting MLE??
plz tell wht this code's giving me MLE???
thanx in advance..

Code: Select all
cut
Last edited by kolpobilashi on Wed Oct 25, 2006 11:27 am, edited 2 times in total.
Sanjana
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
use bits. here is a sample if u want 2 access the X'th bit of a char array.kolpobilashi wrote:yes i understood the problem...but the thing is what should i do then.??
if i don't generate the primes before.....and each time check... that will certainly give TLE.
plz suggest me..
Code: Select all
#define MAX 100000000
char flag[MAX/8];
#define SETBIT(X) (flag[X/8]|=1<<(X%8))
#define GETBIT(X) ((flag[X/8]&(1<<(X%8)))?1:0)
-
- Experienced poster
- Posts: 161
- Joined: Tue Oct 25, 2005 8:38 pm
- Location: buet, dhaka, bangladesh
if you know bitwise operation in C, it will be rather easy using char array as sunny said. better process is using char array of size[MAX/16]. it deals with only odd numbers, as you know even numbers are not prime(except 2). 1st character of the char array represents whether 1, 3, 5, 7, 9, 11, 13, 15 are prime or not, 2nd character represents 17,19,...,31, etc. you can have a look at http://www.shygypsy.com/tools/number.cpp to get the C code
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program
----------------
the world is nothing but a good program, and we are all some instances of the program
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
10311-GOLBACH AND EULER!!! PLZZ HELP!
I am using Miller's Primality test even then its TLE!!! And when i used sieve its MLE!! I read previous posts but i cant understand how they r managing not to MLE!! some one plzz help!
Last edited by <:3)~~ on Wed Dec 27, 2006 6:33 pm, edited 1 time in total.
Dont open a new thread unless there is none. First search your problem. And when creating a new thread try to write the subject like '10311 - Goldbach and Euler'.
Remember that you can use bitwise sieve.
Remember that you can use bitwise sieve.
Ami ekhono shopno dekhi...
HomePage
HomePage