## 10924 - Prime Words

Moderator: Board moderators

New poster
Posts: 3
Joined: Wed Jul 04, 2007 3:05 pm
Location: East West University
How comes 1 a prime number?????????!!!!!!!! that is really funny and joking.

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

### why wa

it show prime num 1
plz help for

Code: Select all

``````deleted

``````
thanks
but in upper post
1,3,5...... odd number denoted by prime number
so i thought 2 is not prime
Last edited by bishop on Tue Jul 10, 2007 9:55 am, edited 1 time in total.

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:
u need to check ur code again.it need too many modification....
u do p[2]=false but 2 is prime....
again u loop from 3 up to 35....but what happen for 4,8,....it is not prime too.
and ur sum is also incorrect for UPPERCASE.check it.

GOOD LUCK
Rocky

starrynight
New poster
Posts: 7
Joined: Mon Mar 05, 2007 3:24 pm

### 10924 WA

excuse me ,can anyone tell me why I got a WA?
because I can't find where I do wrong .
and sorry for my poor English..

Code: Select all

``````#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{

char word[21];
double sum=0;
int i,y,factor;

while(gets(word) != NULL)
{
factor=0;

for(i=0;i<20;i++)
{
if(word[i]>='a' && word[i]<='z')
sum = sum +(word[i]-96);
else if(word[i]>='A' && word[i]<='Z')
sum = sum +(word[i]-38);
}

for (y = 2; y <= sqrt(sum); y++)
{
if ( fmod(sum,y)==0 )
factor++;
}

if (factor == 0)
printf("It is a prime word.\n");
else
printf("It is not a prime word.\n");

}

return 0;
}

``````

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Try this case..

Code: Select all

``````a
b
c
d
e
A
B
C
D
E
``````
My output is..

Code: Select all

``````It is a prime word.
It is a prime word.
It is a prime word.
It is not a prime word.
It is a prime word.
It is not a prime word.
It is not a prime word.
It is a prime word.
It is not a prime word.
It is a prime word.
``````

laicc86
New poster
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

Code: Select all

``````removed*
``````
can anyone help me? i don't know why i got WA for this.
Last edited by laicc86 on Sat Dec 08, 2007 10:00 am, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
gets returns NULL instead of EOF at the end of input..

PS. remove your code after AC..

laicc86
New poster
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm
helloneo wrote:gets returns NULL instead of EOF at the end of input..

PS. remove your code after AC..
thx for helping~ but i still get WA after i changed the EOF to NULL

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
It is very simple problem.
Use the ASCII value & subtract to generate the number check number is prime or not.
For reducing the time u will generate all the prime of the given range before.

ligregni
New poster
Posts: 11
Joined: Thu Nov 29, 2007 12:41 am
Location: Queretaro, M
Contact:

### WA I don't know why!

hi!, this is my code

Code: Select all

``````/* Prime Words */

REMOVED, got AC
``````
I tried all the single letters, the example cases, the test cases here, and I still getting WA with almost no time (sometimes 0.010 or other times 0.000), I also tried not to print the '\n' at the end

Code: Select all

``````if (1)
printf("\n");``````
changed by

Code: Select all

``````if (c!=EOF)
printf("\n");``````
and it is the same.

an EMPY string should NOT to print ANYTHING
1 is prime
print a \n after ALL cases
[/quote]
C: multum in parvo

"a lot since quite few"

http://acmicpc-live-archive.uva.es/nuev ... user=12539

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Contact:

### Re: 10924 - Prime Words

AC.
Last edited by aliahmed on Mon Jan 19, 2009 9:40 pm, edited 1 time in total.

Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Contact:

### Re: 10924 - Prime Words

whats wrong with this code!!!!!!!!!

i got WA.
try my best.but cant find the problem.
plz plz someone help.
here is my code

Code: Select all

``````removed after being AC.
``````
Last edited by sazzadcsedu on Sun Dec 28, 2008 8:51 pm, edited 1 time in total.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

### Re: 10924 - Prime Words

sazzadcsedu wrote:whats wrong with this code!!!!!!!!!

i got WA.
Oh really? I think you should have got compile error with the code you've posted.

After you fix it, you might want to check again this part of your code:

Code: Select all

``````				  memset(prime,0,sizeof(prime));

for(i=2;i<=20;i++)

{
for(j=2;j<=60;j++)

{
prime[i*j]=1;

}
} ``````
E.g. 1018=2*519 is composite, but your code would claim it's not.

Horrible indenting, btw. If it's not caused by a forum bug (tab=3 spaces), I think you really need to learn some good indenting style.

Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Contact:

### Re: 10924 - Prime Words

Infact i made a stupid mistake.
but now got AC.
thanx a lot mf.
need ur help later(comming!!!).
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359

mintae71
New poster
Posts: 18
Joined: Tue Jan 19, 2010 10:50 am

### 10924 - Prime Words

``Removed after got AC``