10924 - Prime Words

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

Moderator: Board moderators

Postby fuad420 » Wed Jul 04, 2007 3:09 pm

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

why wa

Postby bishop » Mon Jul 09, 2007 9:48 pm

it show prime num 1
but still Wrong answer
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.
bishop
New poster
 
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

Postby Rocky » Mon Jul 09, 2007 11:48 pm

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
User avatar
Rocky
Experienced poster
 
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

10924 WA

Postby starrynight » Wed Aug 01, 2007 7:10 am

excuse me ,can anyone tell me why I got a WA?
because I can't find where I do wrong .
thanks in advance :)
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;
}
   
starrynight
New poster
 
Posts: 7
Joined: Mon Mar 05, 2007 3:24 pm

Postby helloneo » Wed Aug 01, 2007 7:51 am

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.
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Postby laicc86 » Wed Dec 05, 2007 7:17 am

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.
laicc86
New poster
 
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

Postby helloneo » Wed Dec 05, 2007 8:23 am

gets returns NULL instead of EOF at the end of input..


PS. remove your code after AC..
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Postby laicc86 » Wed Dec 05, 2007 12:30 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 :(
laicc86
New poster
 
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

Postby turcse143 » Wed Dec 19, 2007 5:33 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.
turcse143
Learning poster
 
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

WA I don't know why!

Postby ligregni » Mon Dec 24, 2007 9:44 pm

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.

Please HELP!!!

I have SOME ADVICES!

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
ligregni
New poster
 
Posts: 11
Joined: Thu Nov 29, 2007 12:41 am
Location: Queretaro, M

Re: 10924 - Prime Words

Postby aliahmed » Wed Oct 29, 2008 12:50 am

AC.
Last edited by aliahmed on Mon Jan 19, 2009 9:40 pm, edited 1 time in total.
aliahmed
New poster
 
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Location: CUET, Chittagong, Bangladesh

Re: 10924 - Prime Words

Postby sazzadcsedu » Sun Dec 28, 2008 12:34 am

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.
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Re: 10924 - Prime Words

Postby mf » Sun Dec 28, 2008 3:32 am

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.
mf
Guru
 
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

Re: 10924 - Prime Words

Postby sazzadcsedu » Sun Dec 28, 2008 8:48 pm

Infact i made a stupid mistake.
but now got AC.
thanx a lot mf.
need ur help later(comming!!!).
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Re: 10924 - Prime Words

Postby DD » Mon Mar 14, 2011 12:32 am

I think the only thing we should take case for this problem is that "1 is prime".
Have you ever...

    Wanted to work at best companies?
    Struggled with interview problems that could be solved in 15 minutes?
    Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
DD
Experienced poster
 
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

PreviousNext

Return to Volume CIX

Who is online

Users browsing this forum: No registered users and 0 guests