10852 - Less Prime

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

Moderator: Board moderators

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

ibrahim wrote:I can't understand what the question is trying. Can anybody please explain it ? :(
How can 101 output is 53 ?
You are looking for a prime number x≤n, such that n%x is maximum. (and 101%53=48, the most you can get)
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10852 input

Post by Martin Macko »

ThanhNhan wrote:That the input for p10852 contains n < 100 is incorrect. Shouldn't it be fixed ?
I think, it should be fixed... At least in the problem statement...
Possibly, we could ask problemsetter to fix it...
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim »

Thanks, AC
alecliu
New poster
Posts: 1
Joined: Thu Jun 01, 2006 9:27 am
Contact:

How can it be solved in 0.000sec?

Post by alecliu »

How can it be solved in 0.000sec?
Please give me some hit, thank you!
Neli
New poster
Posts: 7
Joined: Thu May 03, 2007 8:35 am
Location: Sylhet
Contact:

10852 - Less Prime

Post by Neli »

I just checked the condition:
while(prime[j]*2<=n)
j++;
I thought that was enough.But got wrong answer.
Plz help.
mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish »

>>Neli
Ur solution is ok. so u should check the other parts of the code specially the prime generating part.
If u don't get any coz of getting WA then i think the best idea to recode it.
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

caution: 10852 - Less Prime

Post by sazzadcsedu »

input can be less than 100.
for input 1 & 2
just output -1;
others r according to ur (correct)algorithm.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
sayed
New poster
Posts: 2
Joined: Tue Sep 01, 2009 11:47 am
Location: Bangladesh
Contact:

Re: caution: 10852 - Less Prime

Post by sayed »

input and output is correct bt why wrong answer??

Code: Select all

#include<stdio.h>

int main()
{
	int i,b,flag,a,c,test,g,p;

	scanf("%d",&test);

	while(test--)
	{
		scanf("%d",&c);

		a=2;
		g=0;
		p=(c/2)+1;
		for(b=p;b<=c;b++)
		{
			flag=0;
			for(i=2;i<=(b/2);i++)
				if((b%i)==0)
				{
					flag=1;
					break;
				}

			if(flag==0)
			{
				printf("%d\t",b);
				g++;
			}
			if(g==1)
				break;
		}
		printf("\n");
	}
return 0;
}
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10852 - Less Prime

Post by uDebug »

CDiMa wrote:Look out for input values under 100.
This was quite misleading / confusing.

On the input, the problem statement clearly states
For each test case, there is a line with a number N, 100 ? N ? 10000.
There really are no "gotchas". It's all quite straightforward.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: caution: 10852 - Less Prime

Post by uDebug »

sayed wrote: input and output is correct bt why wrong answer??
You're nearly there.

Change

Code: Select all

printf("%d\t",b);
to

Code: Select all

printf("%d",b);
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
Post Reply

Return to “Volume 108 (10800-10899)”