Page 3 of 14

PE why ?help me.

Posted: Wed Dec 10, 2003 11:03 am
by problem
[c]
PE help me plz.here is my source code.

/* @JUDGE_ID: xxxxxx 160 C++ */

#include<stdio.h>
#include<string.h>
int main()
{
long int i,j,n,k,p=0;
static int x[500];
memset(x,0,500);
scanf("%ld",&n);
while(n>0)
{ for(i=2;i<=n;i++)
{ j=i;
for(k=2;k<=i;k++)
{ while(j%k==0)
{ ++x[k];
j/=k;
}
}
}
printf("%2ld! = ",n);
for(i=0;i<=99;i++)
{
if(x)
{
p++;
if(p==16&&n==100)
{
printf("\n ");
p=0;
}
if(p==16)
{
printf("\n ");
p=0;
}
printf("%2d ",x);
}
/* if(n>=53&&p>=15)
{
if(n==100)
printf("\n ");
else
printf("\n ");
p=0;
} */
}
memset(x,0,500);
printf("\n");
scanf("%ld",&n);
p=0;
}
return 0;
}

[\c]

160 why WA?i think my output is exactly as sample:(

Posted: Mon Feb 02, 2004 2:34 pm
by Morning
[cpp]
#include "stdio.h"

int main(int argc, char* argv[])
{
int num,temp,point,done,max,change;
int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int numOfPrime[25];
while(scanf("%d",&num))
{
max=0;
if(num==0) break;
for(temp=0;temp<25;temp++)
numOfPrime[temp]=0;
for(done=2;done<=num;done++)
{
temp=done;
while(temp!=1)
{
for(point=0;point<25 && prime[point]<=temp;point++)
{
if(temp%prime[point]==0)
{
temp/=prime[point];
numOfPrime[point]++;
if(point>max) max=point;
}
}
}
}
printf("%3d! =",num);
for(temp=0,change=0;temp<=max;temp++)
{
if(numOfPrime[temp]!=0)
{
change++;
printf("%3d",numOfPrime[temp]);
if(change==15)
{
change=0;
printf("\n ");
}
}
}
if(change!=15) printf("\n");

}
return 0;
}

[/cpp]

Posted: Tue Feb 03, 2004 6:37 am
by Frostina
why it gets wa ? plz..

[c]#include <stdio.h>
#include <math.h>
int prime[40];
int is_prime(int n) {
int i;
for (i=0;prime*prime<=n;i++)
if (!(n%prime))
return 0;
return 1;
}
void make_table(void) {
int i, index = 1;
prime[0] = 2;
for (i=3;i<=150;i+=2)
if (is_prime(i))
prime[index++] = i;
}
int main(void) {
int n, i, t, j;
make_table();
while (scanf("%d",&n)==1) {
if (!n) break;
printf("%3d! =",n);
for (i=t=0;prime<=n;i++,t=0) {
for (j=1;;j++) {
if ((int)pow(prime*1.0,j*1.0)>n)
break;
t+=n/(int)pow(prime*1.0,j*1.0);
}
printf(" %3d",t);
if (!(i%14)&&i) printf("\n ");
}
putchar('\n');
}
return 0;
}
[/c]

Re: 160 why WA?i think my output is exactly as sample:(

Posted: Tue Feb 03, 2004 3:43 pm
by junbin
I tested your code again my AC program and I get the following:

Your output:

100! = 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1


My output:

100! = 95 48 22 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1

Posted: Tue Feb 03, 2004 3:45 pm
by Morning
Thanks so much,i'll recode it

Posted: Tue Feb 03, 2004 4:53 pm
by Morning
hey,it's interesting,but seems ur AC code is wrong,here's some data,1st is the number who can be divided by 2 in 100!,2nd is the times that it can be divided by 2:
2 1
4 2
6 1
8 3
10 1
12 2
14 1
16 4
18 1
20 2
22 1
24 3
26 1
28 2
30 1
32 5
34 1
36 2
38 1
40 3
42 1
44 2
46 1
48 4
50 1
52 2
54 1
56 3
58 1
60 2
62 1
64 6
66 1
68 2
70 1
72 3
74 1
76 2
78 1
80 4
82 1
84 2
86 1
88 3
90 1
92 2
94 1
96 5
98 1
100 2
[cpp]
#include"iostream.h"
int main()
{
int a,b,c;
a=1;
c=0;
while(a!=0)
{
cin>>a>>b;
c+=b;
cout<<c<<endl;
}
}[/cpp]

copy the data and as the input of this program,u will find 97 should be right answer
????????

Posted: Tue Feb 03, 2004 6:46 pm
by junbin
oops.. you're right... when I determine primes, I used an auto generator to count up to 99.. so 100 is flagged as prime by mistake. :p

Now we know 100 is not in the data set.. :)

Anyway, the reason is very obvious if you make a input file with all 100 numbers and pipe the output to a file and then edit the file.

Posted: Tue Feb 03, 2004 6:50 pm
by Morning
then it will be another problem maybe difficult :wink:

Posted: Thu Feb 05, 2004 7:31 am
by Morning
so anyone can provide ur AC code to me to let me compare the output with mine?Please mail to MorningCX@hotmail.com
thanks a lot

Posted: Thu Feb 05, 2004 2:10 pm
by junbin
Morning wrote:so anyone can provide ur AC code to me to let me compare the output with mine?Please mail to MorningCX@hotmail.com
thanks a lot
You don't need someone else's code... just genereate a test data file from 2 to 100. Run your program with this and output to a FILE (not to standard io). Edit the file and look carefully from top to bottom.. you cannot miss the mistake.

Posted: Thu Feb 05, 2004 2:14 pm
by Morning
I've done it but i can't find the mistake,for the out-put code algrithm is the same as the WA code.So i should have another AC code. :-?
Have u correct ur code?

Posted: Thu Feb 05, 2004 3:46 pm
by junbin
Morning wrote:I've done it but i can't find the mistake,for the out-put code algrithm is the same as the WA code.So i should have another AC code. :-?
Have u correct ur code?
I've corrected my code.. it's still AC.. the judge does not test 100.

Anyway, take a very careful look at your output.. it should be around 30-60.. the answers are correct, at least the maths part. it's the OUTPUT that is wrong.

160: Factors and factorials..... WA Help Please... (Now AC)

Posted: Wed Feb 25, 2004 6:33 am
by aakash_mandhar
What is wrong with my code.. I guess allignement.. It seems to work fine and logic is simple and infact it also works for inputs greater than 100 but i go WA... Please can anyone help me or tell me in which case it fails..

Thx a lot in advance
Aakash


[cpp]
Code removed. Never mind i got it accepted. The problem was that you can print only 15 digits on each line.. Silly me :) This might help others..
[/cpp]

Posted: Wed Feb 25, 2004 6:49 am
by UFP2161
These should be right justified in fields of width 3 and each line (except the last of a block, which may be shorter) should contain fifteen numbers. Any lines after the first should be indented. Follow the layout of the example shown below exactly.

NEEEEDDDD HELP PROBLEM 160 pleaseeeeeeeeee

Posted: Wed Apr 07, 2004 4:41 am
by Ghust_omega
[java]
hi!
someone please help me with the problem 160 i have compile error in JAVA and I dont know why, if someone can tell me whats wrong, I apriciate that here my source code

import java.io.*;
import java.util.*;

class Main
{
static String ReadLn (int maxLg) // utility functito read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}

public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}

void Begin()
{
String input;
StringTokenizer idata;
int a=0;
Vector numeros= new Vector();

while ((input = Main.ReadLn (255)) != null)
{
idata = new StringTokenizer (input);
a = Integer.parseInt (idata.nextToken());
if(a==0){
break;
}
if(a==1){System.out.println(" "+a+"!"+" = "+1);}
else {

Vector v= new Vector();
int [] a1= new int [a];
int j=2;
for(int x=0;x!=a-1;x++){
a1[x]=j;
j++;
}
int i=0,m=0,l=0;
while(i!=a-1){
j=i+a1;
if(a1==1) {i++; }
else { Double k= new Double((a-1)/a1);
m= k.intValue();
v.add(new Integer(1));

do{
if(j<=a-1&&a1[j]!=0){
if(a1[j]%a1==0){
a1[j]=a1[j]/a1;

Integer aux= (Integer)v.lastElement();
int u = aux.intValue();
v.remove(v.lastElement());
u++;
v.add(new Integer(u++));
}
else{
l++;
j=j+a1;
}

}
else break;
}
while(j<=a-1);
i++;
}

}
int contador=0;
if(new Integer(a).toString().length()==1)System.out.print(" "+a+"!"+" =");
if(new Integer(a).toString().length()==2)System.out.print(" "+a+"!"+" =");
if(new Integer(a).toString().length()==3)System.out.print(a+"!"+" =");
for(int p=0;p!=v.size();p++){
if(contador==15){
System.out.print("\n");
System.out.print(" ");
}
if(v.get(p).toString().length()==1)System.out.print(" "+v.get(p));
if(v.get(p).toString().length()==2)System.out.print(" "+v.get(p));
if(v.get(p).toString().length()==3)System.out.print(v.get(p));
contador++;
}
System.out.print("\n");
}
}

}
} [/java]