136 - Ugly Numbers

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

Moderator: Board moderators

IncreasE
New poster
Posts: 2
Joined: Sun Mar 05, 2006 5:39 am

136 Ugly Number Presentation Error

Post by IncreasE »

Code: Select all

***Solve
It always "Presentation Error". Why ? Help Me Pls TT :(
Last edited by IncreasE on Wed Mar 08, 2006 7:52 am, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

You should print '\n' at the end of line.
IncreasE
New poster
Posts: 2
Joined: Sun Mar 05, 2006 5:39 am

Post by IncreasE »

Thank you very much for you help. :)
OmarOthman
New poster
Posts: 4
Joined: Mon Apr 03, 2006 1:05 am
Location: Cairo - Egypt
Contact:

Compile Time Error - Problem 136

Post 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.
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post 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.
OmarOthman
New poster
Posts: 4
Joined: Mon Apr 03, 2006 1:05 am
Location: Cairo - Egypt
Contact:

Post by OmarOthman »

Thanks very much for your fast and detailed reply. It worked, but the answer was wrong :oops: ... ( But this is my problem now, not yours :D ). 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.
bsd31378
New poster
Posts: 1
Joined: Sun Apr 16, 2006 6:40 am

Post by bsd31378 »

Thanks your help
darkos32
New poster
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia
Contact:

136 TEL ?

Post 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.
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

accepted [136]!

Post by newton »

got AC.
thanks to all.

Code: Select all


for( ; ; )
     printf("Thank you ");

[/code]
Last edited by newton on Sat Aug 19, 2006 8:00 am, edited 2 times in total.
DP
Learning poster
Posts: 62
Joined: Sun Aug 13, 2006 9:15 am
Location: Bangladesh
Contact:

Post by DP »

hmm. really novice. :wink:

Code: Select all

OK just use double instead of long long
bye
Bluefin
New poster
Posts: 20
Joined: Sat Jul 08, 2006 3:39 pm
Contact:

Post 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 !! :lol:
"It's nice to be important, but it's more important to be nice"

http://bluefintuna.wordpress.com/
nev4
New poster
Posts: 15
Joined: Sun Apr 30, 2006 10:19 am
Location: Lithuania

Post 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.
Hio
New poster
Posts: 2
Joined: Sun Feb 11, 2007 10:07 pm

The 1500th ugly number

Post 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
Hio
New poster
Posts: 2
Joined: Sun Feb 11, 2007 10:07 pm

1500th ugly number

Post by Hio »

I got the answe <removed> is it right?
Because when i submited the code the online-judge said "Wrong Answer".
ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

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

Return to “Volume 1 (100-199)”