
967 - Circular
Moderator: Board moderators
Try the cases.
Input:
Output:
Hope these help.
Input:
Code: Select all
373 604773
373 936713
311 655815
-1
Code: Select all
30 Circular Primes.
32 Circular Primes.
32 Circular Primes.
Ami ekhono shopno dekhi...
HomePage
HomePage
967 - Circular TLE
Hi,
I am a n00b here.
My code passes sample tests but I am getting TLE.
Can't think of better method. Please help.
~CODE ACed~
I am a n00b here.

My code passes sample tests but I am getting TLE.
Can't think of better method. Please help.
~CODE ACed~
Last edited by darku on Tue Apr 15, 2008 9:42 am, edited 1 time in total.
Re: 967 - Circular
Code: Select all
/* run loop from i to j */
for(k = i ; k <= j; k++) {
if(!numbers[k])
continue;
count++;
}
Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 967 - Circular
Thank you Jan.
- I got AC 0.250 seconds.
- How can I reduce this time further? Please share some tricks.
- OT: Ami ekhono shopno dekhi... Does it mean "I still dream" ?
- I got AC 0.250 seconds.
- How can I reduce this time further? Please share some tricks.

- OT: Ami ekhono shopno dekhi... Does it mean "I still dream" ?
Last edited by darku on Tue Apr 15, 2008 12:59 pm, edited 1 time in total.
Re: 967 - Circular
You are welcome. To reduce time..darku wrote:Thank you Jan.
- I got AC 0.250 seconds.
- How can I reduce this time furthe?. Please share some tricks.
- OT: Ami ekhono shopno dekhi... Does it mean "I still dream" ?
Code: Select all
res[] is an array
res[x] = number of circular primes from 0 to x.
First calculate res[].
Then for (a, b) the result will be res[b] - res[a-1].

Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 967 - Circular
Hi there
I get all the time TLE, even if I use a static array with all the 42 circulars set. Is it maybe the condition for the while-loop? I cant find any mistake.
I get all the time TLE, even if I use a static array with all the 42 circulars set. Is it maybe the condition for the while-loop? I cant find any mistake.
Code: Select all
int main()
{
int i, j, count;
setCircular();
while ((scanf("%d", &i)) && (i >= 100))
{
scanf("%d", &j);
count = 0;
for (int k = (i & 1) ? i : i + 1; k <= j; k += 2)
{
if (isCircular[k])
count++;
}
if (count == 1)
printf("1 Circular Prime.\n");
else if (count > 1)
printf("%d Circular Primes.\n", count);
else
printf("No Circular Primes.\n");
}
return 0;
}
-
- New poster
- Posts: 1
- Joined: Mon Apr 11, 2011 10:45 am
Re: 967 - Circular
Code: Select all
while(!(l.equals("-1"))){
l = eingabe.readLine();
if(l.contains(" ")){
grenze2 = Integer.parseInt(l.substring(l.indexOf(" ")+1));
grenze1 = Integer.parseInt(l.substring(0,l.indexOf(" ")));
count = 0;
for(int j = grenze1;j<grenze2;j++){
if (Circular[j]){
count++;
}
}
if(count>1)
System.out.println(count + " Circular Primes.");
else if(count==1)
System.out.println("1 Circular Prime.");
else System.out.println("No Circular Primes.");
}
}
it works very well for me at home. at least it stops when i put in "-1" in a single line.
any ideas why it wont for the judge? seems to go on and on and on....