967 - Circular

All about problems in Volume 9. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Post by hamedv » Sun Jul 29, 2007 3:43 pm

no one to help me??? :-?

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

Post by Jan » Sun Jul 29, 2007 7:38 pm

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

Post by hamedv » Mon Jul 30, 2007 11:15 am

thanx :wink:

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

967 - Circular TLE

Post by darku » Fri Apr 11, 2008 11:49 am

Hi,

I am a n00b here. :D

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.

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

Re: 967 - Circular

Post by Jan » Fri Apr 11, 2008 4:44 pm

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

Post by darku » Tue Apr 15, 2008 9:41 am

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
Location: Dhaka, Bangladesh
Contact:

Re: 967 - Circular

Post by Jan » Tue Apr 15, 2008 12:23 pm

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' :D .
Ami ekhono shopno dekhi...
HomePage

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

Re: 967 - Circular

Post by Vanish » Sun Mar 29, 2009 10:25 pm

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

Post by kneifmichmal » Mon Apr 11, 2011 10:51 am

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.");
		}
	}
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....

Post Reply

Return to “Volume 9 (900-999)”