## 160 - Factors and Factorials

Moderator: Board moderators

problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

### PE why ?help me.

[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;
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]
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

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

[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;
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]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
Frostina
New poster
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am
why it gets wa ? plz..

[c]#include <stdio.h>
#include <math.h>
int prime;
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 = 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]
Thanks for your help ! junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am

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

I tested your code again my AC program and I get the following:

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
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
Thanks so much,i'll recode it
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
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
????????
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am
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.
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
then it will be another problem maybe difficult "Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
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
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am
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.
Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China
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?
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
junbin
Experienced poster
Posts: 174
Joined: Mon Dec 08, 2003 10:41 am
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.
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

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

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..

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]
...I was born to code...
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
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.
Ghust_omega
Experienced poster
Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela

### NEEEEDDDD HELP PROBLEM 160 pleaseeeeeeeeee

[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
{
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
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();

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++;
}
else{
l++;
j=j+a1;
}

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

}
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++){
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));