Page 9 of 11
136 Ugly Number Presentation Error
Posted: Sun Mar 05, 2006 5:44 am
by IncreasE
It always "Presentation Error". Why ? Help Me Pls TT

Posted: Sun Mar 05, 2006 8:20 am
by mf
You should print '\n' at the end of line.
Posted: Wed Mar 08, 2006 7:50 am
by IncreasE
Thank you very much for you help.

Compile Time Error - Problem 136
Posted: Mon Apr 03, 2006 1:11 am
by OmarOthman
Hello all,
I'm a beginner with java submissions here and - frankly - I've heard that there are lots of problems with the java compiler. Here's my code to the ugly numbers problem, very simplified to the last result only so that I can ensure the simplicity of the first trial.
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("The 1500'th ugly number is 5624");
}
}
But the compile error says:
04470699_24.java:1: Public class `Main' must be defined in a file
called `Main.java'.
public class Main {
^
1 error
Although I don't even send a file! I paste the code directly at the submission page.
Please reply soon... and thanks in advance.
Posted: Mon Apr 03, 2006 4:47 am
by chunyi81
Delete the word "public" in front of "Main".
Hope this helps.
Putting the word public for a Java class is more useful when you have many packages and you need to make some classes in a package accessible to classes in another package.
Posted: Mon Apr 03, 2006 10:29 am
by OmarOthman
Thanks very much for your fast and detailed reply. It worked, but the answer was wrong

... ( But this is my problem now, not yours

). but please if you know any other silly, well-known compilation errors I'll be very grateful if you can benefit us with your expertise, because indeed all my friends warned me that the java compiler here has got a lot of inconsistencies.
Thanks again and good bye.
Posted: Sun Apr 16, 2006 6:41 am
by bsd31378
Thanks your help
136 TEL ?
Posted: Thu Aug 10, 2006 7:07 am
by darkos32
hi,all.im new user here...i got problems with 136,
this is my source code.
Code: Select all
#include <stdio.h>
long a[1501];
void main(){
int i = 1;
int byk = 1500;
i = 0;
while(i<1500) {
a[i]=0;
i++;
}
i = 1;a[1] = 1;
long hasil = 2;int mulai = 0;
while(i<byk){
bool ada = true;int j = 0;
while(ada){
if(hasil%2==0 || hasil%3==0 || hasil%5==0){
if(hasil%2==0) {
if(hasil/2==2 || hasil/2==3 || hasil/2==5 || hasil/2==1) {
ada = false;
}
else {
j = 0;
while(j<mulai){
if(a[j]==hasil/2) {
ada= false;
j+=mulai+1;
}
j++;
}
//if(a[hasil/2]==1) ada = false;
}
}
if(hasil%3==0) {
if(hasil/3==2 || hasil/3==3 || hasil/3==5 || hasil/3==1) {
ada = false;
}
else {
j = 0;
while(j<mulai){
if(a[j]==hasil/3) {
j+=mulai+1;
ada= false;
}
j++;
}
//if(a[hasil/3]==1) ada = false;
}
}
if(hasil%5==0) {
if(hasil/5==2 || hasil/5==3 || hasil/5==5 || hasil/5==1) {
ada = false;
}
else {
j = 0;
while(j<mulai){
if(a[j]==hasil/5) {
j+=mulai+1;
ada= false;
}
j++;
}
//if(a[hasil/5]==1) ada=false;
}
}
if(!ada) {
a[mulai]=hasil;mulai++;
}
}
hasil++;
}
i++;
//if(i>=byk) printf("%ld",hasil-1);
}
printf("The 1500'th ugly number is %ld.",hasil-1);
}
sorry my code is very bad.coz im still amateur.
anyone can help me please ?thanks.
accepted [136]!
Posted: Sun Aug 13, 2006 3:13 pm
by newton
got AC.
thanks to all.
[/code]
Posted: Sun Aug 13, 2006 4:16 pm
by DP
hmm. really novice.
Code: Select all
OK just use double instead of long long
bye
Posted: Wed Aug 16, 2006 4:03 pm
by Bluefin
There has been a lot of information about Q136 - The Ugly Number
Like this thread:
http://online-judge.uva.es/board/viewto ... hlight=136
I solved this problem a long time ago after reading the thread I gave you!!
And after you solve Q136, you can try Q443. They are similiar !!
Hope it will help !!

Posted: Wed Aug 16, 2006 5:00 pm
by nev4
This problem is easy. You just have to run one loop and check inside if loop counter only divides 2, 3, 5 if so add one to UGLYNR counter(using while and % is easiest).
When u get 1500th just output it according to problem sample output, insert that number and just print out that one statement.
The 1500th ugly number
Posted: Sun Feb 11, 2007 10:14 pm
by Hio
I tried with a straight-to-the-problem solution, i mean i made a procedure that returns 1 if a given number is ugly and 0 otherwize. Well as you can suppose the result needs a lot of time.
The function is that:
int fact[3]={2, 3, 5};
int fact_div(int num1, int st_at);
int fact_div(int num1, int st_at)
{
int i, res, rem;
int start_at1;
div_t div_result;
if (num1==1) return ugnum;
else ugnum=0;
for (i=st_at; i<=2; i++)
{
div_result=div(num1, fact);
res=div_result.quot; rem=div_result.rem;
ugnum=0;
if (rem==0)
{
ugnum=1;
start_at1=i;
fact_div(res, start_at1); i=3;
}
}
return ugnum;
}
If some one can find a way to speed this up. I will be greatfull for help.
Thanks
1500th ugly number
Posted: Wed Feb 21, 2007 10:47 pm
by Hio
I got the answe <removed> is it right?
Because when i submited the code the online-judge said "Wrong Answer".
Posted: Sat Feb 24, 2007 11:39 am
by ranban282
Yes, it is. Are you sure that you are formatting your output correctly? It should be The 1500'th ugly number is<space><number><fullstop><\n>
Remove your answer once you get acc.