## 967 - Circular

Moderator: Board moderators

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am
no one to help me???

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Try the cases.

Input:

Code: Select all

373 604773
373 936713
311 655815
-1
Output:

Code: Select all

30 Circular Primes.
32 Circular Primes.
32 Circular Primes.
Hope these help.
Ami ekhono shopno dekhi...
HomePage

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am
thanx

darku
New poster
Posts: 2
Joined: Thu Apr 10, 2008 9:03 am

### 967 - Circular TLE

Hi,

I am a n00b here.

My code passes sample tests but I am getting TLE.

~CODE ACed~
Last edited by darku on Tue Apr 15, 2008 9:42 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

### Re: 967 - Circular

Code: Select all

/* run loop from i to j */
for(k = i ; k <= j; k++) {
if(!numbers[k])
continue;
count++;
}
Store the numbers. Then print the numbers from i to j. Don't iterate normally because there are too few numbers that are circular.
Ami ekhono shopno dekhi...
HomePage

darku
New poster
Posts: 2
Joined: Thu Apr 10, 2008 9:03 am

### 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" ?
Last edited by darku on Tue Apr 15, 2008 12:59 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

### Re: 967 - Circular

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" ?
You are welcome. To reduce time..

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].
And you are right about 'Ami ekhono shopno dekhi' .
Ami ekhono shopno dekhi...
HomePage

Vanish
New poster
Posts: 1
Joined: Sun Mar 29, 2009 10:03 pm

### 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.

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;
}

kneifmichmal
New poster
Posts: 1
Joined: Mon Apr 11, 2011 10:45 am

### Re: 967 - Circular

Code: Select all

while(!(l.equals("-1"))){
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.");
}
}
i really dont udnerstand why i get TLE...
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....