Page 2 of 2

Posted: Sat Feb 23, 2008 3:41 pm
by turcse143
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.

Re: 11115 - Uncle Jack

Posted: Sat Apr 19, 2008 6:42 am
by andmej
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.

11115 - Uncle Jack - RE

Posted: Sat May 31, 2008 9:39 am
by aeiou

Code: Select all

Removed after ACed!!!!

Re: 11115 - Uncle Jack

Posted: Sat May 31, 2008 10:01 pm
by andmej
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.

Re: 11115 - Uncle Jack

Posted: Wed Jun 04, 2008 5:08 am
by aeiou
To andmej ,

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

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

Re: 11115 - Uncle Jack

Posted: Mon Oct 25, 2010 4:24 pm
by treblih
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!

Re: 11115 - Uncle Jack

Posted: Tue Oct 30, 2012 10:50 pm
by gr81
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;
}

Re: 11115 - Uncle Jack

Posted: Thu Nov 01, 2012 2:05 am
by brianfry713
input:

Code: Select all

1 0
0 0
Output should be 1 in less than 3 seconds.

Re: 11115 - Uncle Jack

Posted: Fri Nov 02, 2012 7:26 pm
by gr81
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.

Re: 11115 - Uncle Jack

Posted: Fri Nov 02, 2012 9:48 pm
by brianfry713
https://ideone.com/qMfWfC
The code you posted times out.

Re: 11115 - Uncle Jack

Posted: Tue Nov 12, 2013 10:00 pm
by brianfry713
The answer is N.pow(D), use bigint.