11115 - Uncle Jack

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

Moderator: Board moderators

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Sat Feb 23, 2008 3:41 pm

yaaaaaa i got it.
in case of d<9 i use pow(n,d);
other case big integer algorithm.

its cause a great fun to me.
''I want to be most laziest person in the world''

User avatar
andmej
Experienced poster
Posts: 158
Joined: Sun Feb 04, 2007 7:45 pm
Location: Medellin, Colombia

Re: 11115 - Uncle Jack

Post by andmej » Sat Apr 19, 2008 6:42 am

Hello,

I'm a Java newbie. Can somebody tell my why does this code generate a Runtime Error? Thanks in advance.

Code: Select all

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

class UncleJack
{
    static BufferedReader stdin;
    static PrintWriter stdout;
    
    public static void main(String[] ss) throws Exception
    {
	Reader rdr = new InputStreamReader(System.in);
	stdin      = new BufferedReader(rdr);
	Writer wtr = new OutputStreamWriter(System.out);
	wtr        = new BufferedWriter(wtr);
	stdout     = new PrintWriter(wtr);
	
	(new UncleJack()).run();
	stdout.close();
    }
        
    void run() throws Exception
    {
    	StringTokenizer t = new java.util.StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(t.nextToken());
		int d = Integer.parseInt(t.nextToken());
    	while (n + d != 0){
    		BigInteger b = new BigInteger(String.valueOf(n));
    		b = b.pow(d);
    		stdout.println(b.toString());
        	t = new java.util.StringTokenizer(stdin.readLine());
    		n = Integer.parseInt(t.nextToken());
    		d = Integer.parseInt(t.nextToken());
    	}
    }
}

Thanks a lot for the help.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.

Are you dreaming right now?
http://www.dreamviews.com

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

11115 - Uncle Jack - RE

Post by aeiou » Sat May 31, 2008 9:39 am

Code: Select all

Removed after ACed!!!!
Last edited by aeiou on Wed Jun 04, 2008 5:06 am, edited 1 time in total.

User avatar
andmej
Experienced poster
Posts: 158
Joined: Sun Feb 04, 2007 7:45 pm
Location: Medellin, Colombia

Re: 11115 - Uncle Jack

Post by andmej » Sat May 31, 2008 10:01 pm

I think the problem is the Big Integer class. The code I posted just before your post also gets a Runtime Error. I changed it to not use BigInteger and got Wrong Answer instead.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.

Are you dreaming right now?
http://www.dreamviews.com

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

Re: 11115 - Uncle Jack

Post by aeiou » Wed Jun 04, 2008 5:08 am

To andmej ,

I think the problem is not with with BigInt usage ...

May be I can send my code to u as a PM !!!

treblih
New poster
Posts: 1
Joined: Mon Oct 25, 2010 4:19 pm

Re: 11115 - Uncle Jack

Post by treblih » Mon Oct 25, 2010 4:24 pm

all the test cases:
1 0
1 1 ...
1 25
2 0 ...
2 25
...
10 0 ...
10 25

my outputs are the same as what UVA TOOLKIT does, but still WA...
why?
thx!

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 11115 - Uncle Jack

Post by gr81 » Tue Oct 30, 2012 10:50 pm

getting TLE...please help..

here is the code..

#include <iostream>
#include <fstream>
#include <string>
#include <string.h>

using namespace std;
typedef int BigN[1000];

BigN a;
BigN result;

void print(BigN num)
{
for(int i = num[0]; i > 0; --i)
cout << num;
cout << endl;
}

int to_int(string &str)
{
int len = str.size();
int dec = 0;
for(int i=0; i < len; ++i)
{
dec = (dec * 10) + (str - '0');
}

return dec;
}

void solve( string &nep, string &cds)
{
int nepw = to_int(nep);
int count = to_int(cds);
int len = nep.size();
a[0] = len;
for(int i = 1; i <= len; ++i)
a = nep[len-i] - '0';

while(--count)
{
int len = a[0];
a[0] = 0;
int c = 0;
for(int i=1; i <= len || c; ++i)
{
int newdig = (a * nepw) + c;
if( newdig > 9)
{
a = newdig % 10;
c = newdig / 10;
}
else
{
a = newdig;
c = 0;
}
++a[0];
}
}
print(a);
}

int main()
{
string nep, cds;

while( cin >> nep >> cds )
{
if(nep[0] == '0' && cds[0] == '0')
break;
solve(nep, cds);
memset(&a, 0, sizeof(a));
nep.clear();
cds.clear();
}

return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11115 - Uncle Jack

Post by brianfry713 » Thu Nov 01, 2012 2:05 am

input:

Code: Select all

1 0
0 0
Output should be 1 in less than 3 seconds.
Check input and AC output for thousands of problems on uDebug!

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 11115 - Uncle Jack

Post by gr81 » Fri Nov 02, 2012 7:26 pm

hi, output is 1, i have tested with my program, but still getting WA, if WA gets corrected, then I will look into TLE if any.
any suggestion.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11115 - Uncle Jack

Post by brianfry713 » Fri Nov 02, 2012 9:48 pm

https://ideone.com/qMfWfC
The code you posted times out.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11115 - Uncle Jack

Post by brianfry713 » Tue Nov 12, 2013 10:00 pm

The answer is N.pow(D), use bigint.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 111 (11100-11199)”