CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » The Rise and Fall of Power

The Rise and Fall of Power

Problem code: MARCHA4

  • Submit
  • All Submissions

All submissions for this problem are available.

The following problem appeared in the CodeChef March '09 Challenge.

Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly keep Johnny occupied for a while if he were to do it honestly. But Johnny knows that the teacher will certainly get bored when listening to his answer, and will sleep through most of it! So, Johnny feels he will get away with reading only the first k digits of the result before the teacher falls asleep, and then the last k digits when the teacher wakes up.

Write a program to help Johnny to compute the digits he will need to read out.

Input

The first line contains t, the number of test cases (about 30000). Then t test cases follow.

Each test case consists of one line containing two numbers n and k (1 ≤ n ≤ 109, 1 ≤ k ≤ 9). It is guaranteed that k is not more than the number of digits of nn.

Output

For each test case, print out one line containing two numbers, separated by a space, which are the first and the last k digits of nn.

Example

Input
2
4 2
9 3

Output
25 56
387 489

Author: admin
Date Added: 18-03-2009
Time Limit: 4 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

malcolmc @ 17 Jun 2009 10:46 PM

Does the given time limit indicate compile time? Or the time for producing the output?

jaganr @ 20 Jun 2009 01:14 AM

Is there anyway to limit the input size? i could not use double (in java) for such a big number. Mine should work for n value till 140 (where n^n is within double limit). Any help please

meowmix @ 26 Jun 2009 03:09 PM

@jagan

Have you considered using java.math.BigInteger ?

-Zach

i0exception @ 26 Jun 2009 05:21 PM

@jagan It is possible to code this in C . You can't possibly store that large a number in a double. Think of other ways to get the required result.

Any suggestions for testing

ridiculousfish @ 20 Sep 2009 02:53 PM
Any suggestions for testing values in the range 10^9? Wolfram Alpha, python, etc. won't calculate values beyond ~ 10^8.

long long in c/c++ can store

admin @ 21 Sep 2009 01:42 PM
long long in c/c++ can store values upto 10^18. So can integers in Python and in Java.

Sorry, I was unclear. I was

ridiculousfish @ 21 Sep 2009 03:23 PM
Sorry, I was unclear. I was looking for suggestions for verifying whether my code produces the correct initial 9 digits of N^N, for N on the scale of 10^9. One billion raised to itself is much larger than a long long can store, and Wolfram Alpha stops giving decimal approximations of N^N for N around 30 million.

Hi, my solution is being

porsh @ 29 Sep 2009 11:05 PM
Hi, my solution is being judged as wrong answer. Here is a set of input and output my code produces. Input : 9 4 2 9 3 999 5 457474575 9 1000000000 9 999999999 9 19 9 28 8 27 1 Output: 25 56 387 489 36806 98999 278661176 380859375 100000000 000000000 367880063 999999999 197841965 589123979 33145523 05812736 4 3 Can anybody confirm whether the output produced is correct or not? In case its correct, please provide some more critical cases to test for.

@codechef admin: My

porsh @ 30 Sep 2009 12:34 AM
@codechef admin: My submissision with id#99526 for this problem is judged as "compile error". The solution compiles and runs on my system using g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3. What can be the possible reasons?

There is a problem with

admin @ 30 Sep 2009 02:24 PM

There is a problem with overloading the pow() function.

@aniruddha: thanks :). It has

porsh @ 30 Sep 2009 05:17 PM
@aniruddha: thanks :). It has been troubling me for long.

hello admin.. I am new to

Jaydip Jadav @ 26 Oct 2009 06:25 PM

hello admin..

I am new to codechef..I am working on my first problem "The Rise and Fall of Power"..I saw in the FAQ's that the file should be names Main.java...and i think that, the only file my solutions should have is Main.java..no more class files...please correct me if i am wrong..

thank, Jaydip


Yes, that is correct. Name

admin @ 26 Oct 2009 07:26 PM

Yes, that is correct. Name your class as Main.

hello admin, I was working on

Jaydip Jadav @ 27 Oct 2009 05:25 PM

hello admin,

I was working on this problem using Java (1.5), I am testing my solution for larger numbers like 1000000000...but i think due to the known bugs as listed below, the performance is getting too slow...is it possible to solve this using Java...

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4646474

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4641897

Hello Admin,   Please check

Jaydip Jadav @ 27 Oct 2009 06:33 PM

Hello Admin,

 

Please check my submitted solution and inform me if the way of taking user inputs one case at a time and displaying the result output to the console cause the result "Time limit exceeded"...or something else..

Thanks,

Jaydip

hey suppose if thwe input

mohitgenii @ 1 Nov 2009 04:22 PM

hey suppose if thwe input is

1

100 5

then shud the output be

10000 00000

or

10000 0

Any ideas??

hi admin .. isn't cout , cin

abhayjit @ 12 Nov 2009 03:26 AM

hi admin .. isn't cout , cin , iostream recognizable in c++ with linux .  i am using windows . any substitute??it is giving compilation error but program is compiling successfully in my pc

They work perfectly fine

triplem @ 12 Nov 2009 05:45 AM

They work perfectly fine (though are extremely slow, so you really shouldn't use them). Perhaps you are doing something like forgetting using namespace std; or something else to cause a compile error.

Hi all, I am getting time out

sayan_pakhi @ 17 Nov 2009 02:24 PM

Hi all,

I am getting time out result.

Is it possible to get single threaded optimal solution for this problem.

Hi all, Is anyone get the

sayan_pakhi @ 18 Nov 2009 03:38 PM

Hi all,

Is anyone get the single threaded correct solution for this problem..

Hi all, Is it possible single

sayan_pakhi @ 19 Nov 2009 02:50 PM

Hi all,

Is it possible single threaded accepted solution for this problem.

I have submitted a solution which is showing time out.

I optimize my code enough. still it is showing same.

Should i go for multi-threading??

plz give me hints..

You never need to write a

triplem @ 19 Nov 2009 03:38 PM

You never need to write a multithreaded solution for any of these problems.

Hi Admin, I have tried

rajatag12 @ 23 Nov 2009 04:58 PM

Hi Admin,

I have tried multiple solutions to this problem. As discussed in the blog, if my solution is "numerically-correct" and which it is, it should not give WAs. I see that there was some problem with the test data earlier. Is it resolved ?

My output for the input set that Shishir Mittal has posted above matches with his. So there's a stronger reason to believe that my code is giving correct output.

Please check and let me know.

ADMIN ... i am getting

abhayjit @ 25 Nov 2009 10:11 PM

ADMIN ... i am getting runtime error for my code ... can u plz tell why ... it's working on my system

@Abhyajit Please read the FAQ

admin @ 26 Nov 2009 01:49 PM

@Abhyajit Please read the FAQ and www.codechef.com/wiki

Hi Aniruddha, I have been

arun88m @ 28 Nov 2009 03:58 AM

Hi Aniruddha,

I have been working on this problem for very long time. Its working fine on my computer even for very large values. But here its saying wrong answer. I think the error must be with the first part of output i.e the first k digits of the number. It would be very helpful if you can tell me for what test cases its failing. Or any suggestion in this direction would be helpful.

Thanks,

Arun

in Java if an exception like

abhayjit @ 28 Nov 2009 05:06 AM

in Java if an exception like arrayindexoutofbound occurs in a submitted solution will the judge show it as WA or run time error ??

That is exactly what runtime

triplem @ 28 Nov 2009 05:13 AM

That is exactly what runtime error means.

i have got the idea of the

shivmitra @ 12 Dec 2009 07:58 PM

i have got the idea of the problem clear..my code is giving correct output for some cases but for some cases there is rounding off error as i am using log to solve the prob.i have read abt adding epsilon to counter tht error in uva forum...bt didnt get it..can anyone expain abt this a bit more..giving some example or some url abt it...

@admin I am trying to submit

rohitmanglik @ 14 Jan 2010 10:33 PM

@admin I am trying to submit my solution in php. Can you please tell me what error I am doing. The code runs perfectly in my laptop. Can I post my code here?

I submitted solutions for some other problems which takes a lot of memory for php in comparison to c. for same algo, I also had the timeout error for the same code of C/C++/Jave (Successfully compiled programs) written by some1 else when I change the syntax to PHP

can any one plz confirm that

neel @ 23 Jan 2010 05:44 PM

can any one plz confirm that the output given by sishir mittal given above is correct or not

my output is matching with his output by i am getting WA. So plz confirm whether his output is corret or not

my program gives the same

alok_itbhu @ 29 Jan 2010 09:01 PM

my program gives the same output as given by shishir mittal but i am getting WA.

please anyone confirm whether the output is correct or not

@Alok I am also getting the

cool.sesh @ 31 Jan 2010 12:49 PM

@Alok

I am also getting the same o/p but its showing WA....

@admin Is it possible to

atm242001 @ 5 Feb 2010 10:46 AM

@admin

Is it possible to code this problem in Java? As using Long we can store 10^18. and double 10^308. here we have to deal with 10^9 raised to 10^9.

If we use BigInteger then Performance time goes down due to bugs in Java 1.5

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4646474

 

 

It is impossible to calculate

triplem @ 5 Feb 2010 11:11 AM

It is impossible to calculate the full value of n^n in any language and get accepted within the time limit. That is not the approach you are supposed to take in this problem.

@ Admin, I am unable to get

gurpreet_09 @ 6 Feb 2010 09:44 AM

@ Admin,

I am unable to get any idea for this problem . Plzzzzzzzzz try to provide the tutorial for this problem :P .

@stephen so  some other

atm242001 @ 6 Feb 2010 09:50 AM

@stephen

so  some other approach is to be used to calculate full value or there is no need of calculating full value(answer could be obtained without calculating full value)?

As I said, calculating the

triplem @ 6 Feb 2010 12:49 PM

As I said, calculating the full value is impossible. You must use another approach.

i am getting the right

niloy_padfoot @ 12 Feb 2010 02:04 AM

i am getting the right outputs but a run time error. I have coded in simple c++ but used recursion to calculate the last k digits. Is it because of the recursion that I am getting runtime error?

I am facing a precision

yashumayank @ 23 Feb 2010 07:19 PM

I am facing a precision problem here. Not able to get the last digit from the first digits. I have tried 6 approaches but could only get the precision till first 8 digits at best. Any suggestions.

Chefs, Need a clarification:

rockypg @ 1 Mar 2010 09:58 AM

Chefs, Need a clarification: Are all the 30000 testcases required to complete within the 4 allowed seconds? Or is it a maximum of 4 seconds per test case?

FAQ

triplem @ 1 Mar 2010 11:40 AM

FAQ

faq! thanks, should've done

rockypg @ 1 Mar 2010 12:18 PM

faq! thanks, should've done that first.

 

Its interesting how there isn't even a single successful Java solution to this problem. Time to abandon the libraries I suppose - too slow!

Can any one provide me the

cpp_vs_cc @ 2 Mar 2010 07:49 PM

Can any one provide me the o/p for the large value actually i wanna know whether my programe is running correct or not.

leg eg: give me the o/p for K=84246793

You can use Wolfram

rockypg @ 2 Mar 2010 08:00 PM

You can use Wolfram Alpha(http://www.wolframalpha.com/) to check your answers

@BorT btw K has to be <=9

rockypg @ 2 Mar 2010 08:01 PM

@BorT btw K has to be <=9

Dangit, more java

rockypg @ 3 Mar 2010 05:37 AM

Dangit, more java optimizations, still out of time.

Hey Stephen, you're a Java dude. and I see you don't have this problem in your list, want to share ideas?

@rockypg unable to find the

cpp_vs_cc @ 5 Mar 2010 10:14 AM
@rockypg unable to find the link on http://www.wolframalpha.com/ for calculation can u give the link..

is there any need for error

cpp_vs_cc @ 5 Mar 2010 10:51 AM
is there any need for error correction in the calculation of log and exp ??

@admin N=84246793(

cpp_vs_cc @ 5 Mar 2010 12:27 PM

@admin

N=84246793( random)

provide me output. for any large number i want to check

for N=594859374,K=9 o/p

cpp_vs_cc @ 6 Mar 2010 02:18 PM

for N=594859374,K=9

o/p =321824352 095142400

is this o/p is correct can any one can help

for N=594859374,K=9 o/p

cpp_vs_cc @ 6 Mar 2010 02:19 PM

for N=594859374,K=9

o/p =321824352 095142400

is this o/p is correct can any one can help

AC Outputjunk@debian:~$ echo

navinp @ 24 Mar 2010 09:11 PM

AC Outputjunk@debian:~$ echo 1 19423474 8 | ./a.out
16307491 26110976
junk@debian:~$ echo 1 19423474 9 | ./a.out
163074912 826110976
junk@debian:~$

@everyone i have method to

dabbcomputers @ 24 Apr 2010 12:29 AM

@everyone

i have method to calculate higher n^n but while we calculate 10^9 is near about 9*10^9 decimal digit and the code cross memory usage limit then how we can store it in memory...???

Trying to calculate the full

triplem @ 24 Apr 2010 03:08 AM

Trying to calculate the full value is impossible. You have to figure out a way of just calculating the digits you need.

@Admin : I have been trying

spunkycoder @ 24 Apr 2010 02:44 PM

@Admin :

I have been trying this problem for quite a while now ... have made a few sumissions. I am getting "wrong answer" each time. Can you please provide me with some help / hint ?

Thanks :)

@ admin : I tried a new

spunkycoder @ 25 Apr 2010 01:55 AM

@ admin :

I tried a new approach to the solution. My code ran for a longer time but yet again - I got "Wrong Answer" . Can u plzz help me out ?? Where am i going wrong ?

@admin if the input is 10

ayan_2587 @ 7 Jun 2010 10:18 PM

@admin

if the input is

10 3

then should the answer be

100 000

or

100 0

The problem works fine on my

ayan_2587 @ 7 Jun 2010 10:43 PM

The problem works fine on my system but i keep getting WA here..

Please help..am I missing some special test cases ??

@admin my submission is

rekbun @ 6 Aug 2010 05:45 PM

@admin

my submission is giving a run time error

 

plz tell me the reason

 

Hello admin can u just have a

shadow @ 25 Aug 2010 10:10 PM

Hello admin can u just have a look at this code I am sure that is right but it gives wrong answer!!

http://www.codechef.com/viewsolution/314425

Hello Admin Please check the

shadow @ 26 Aug 2010 03:32 PM

Hello Admin

Please check the above link!!

Same question again . Should

gunjanbansal @ 7 Oct 2010 07:48 PM

Same question again .

Should the answer for 10 3 be 100 000 or 100 0 ??

I think i am having precion

gunjanbansal @ 7 Oct 2010 09:34 PM

I think i am having precion problems, any hints i am using double and unsigned long long int . Calculating only first k and last k digits. my solution is at http://www.codechef.com/viewsolution/352153

@ Admin, could you please let

avinash1 @ 13 Oct 2010 05:37 PM

@ Admin, could you please let me know what is the problem in my submitted solution, since I am getting WA which I think shouldn't be the case. http://www.codechef.com/viewsolution/357085

@admin please check these two

vfix @ 13 Oct 2010 06:00 PM

@admin please check these two links
http://www.codechef.com/viewsolution/349188
http://www.codechef.com/viewsolution/351625

 

Hey... my code is in

balanivash @ 17 Oct 2010 01:15 AM

Hey...

my code is in python... Have tried a lot of time, the algo is correct and is executing within the time limit... Have tried most of the test case and get the correct answers even for the worst ones. dont know what the problem is.... can you pls help!!!!

@admin- pls check this

Cybertooth @ 21 Oct 2010 05:38 PM

@admin- pls check this link

http://www.codechef.com/viewsolution/362942

can u pls tell me where i'm going wrong.. it seems to be workin fine on my comp...

@^^ oops i dint mean to make

Cybertooth @ 21 Oct 2010 05:39 PM

@^^ oops i dint mean to make it so big.. :P

To Admins: I don't know how

ujjwal_kumar @ 30 Oct 2010 01:03 AM

To Admins:

I don't know how far the test cases are correct, but for first k digits I am using first k digits of 10^(fraction(nLog10(n))). Here are my observations:

Any number like n=457474575, 10^(fraction(nLog10(n))) = 2.7866096861492488724505088885778 as per windows calculator. But, in my code, the long double precision is only upto 15 places of decimal. So, when Log10 (15 places of decimal) is multiplied with a 9 digit number, i.e. 457474575, the correctness of (fraction(nLog10(n))) is only upto 6 places of decimal. Hence, when I raise the fraction to 10^fraction, I have a result which is correct to only 4 places of decimal.

I almost broke my head for the last two days to make the 10^fraction correct upto 9 places, but couldn't succeed. After repeated attempts, I was successful to be precise upto 8 places of decimal.

Guess what, when I submitted the 8 places decimal precise code, my code was repeatedly rejected as "wrong answer", but when I submitted the 4 place precise answer, my code was accepted.

For n = 457474575,

Windows calculator ans = 2.7866096861492488724505088885778 (precise upto 31 places of decimal)

8 places precise ans = 2.78660965 (rejected multiple times)

4 places precise ans = 2.78661176 (accepted)

 

I don't know how the test cases are determined, but here I can definitely say they are faulty here. I am new to CodeChef platform, and I was redirected to this puzzle from Directi carrers page. I am sorry to say that I am utterly disappointed as a new user, I worked hard on this problem for 2 days to make it 8 places precise, only to find those test cases are not considered here.

@Ujjwal you should read

vfix @ 30 Oct 2010 01:52 AM

@Ujjwal you should read this

http://discussed.codechef.com/showthread.php?t=115

@Ujjwal - I'm afraid there is

triplem @ 30 Oct 2010 02:26 AM

@Ujjwal - I'm afraid there is nothing wrong with the test cases (which do include ones like you mentioned). I'm not sure what you are using to compile your code, but on codechef and most compilers, long double has 18 decimal places of accuracy, compared to a normal double which has 15.

Your accepted code correctly outputs 278660968 for the test case you mentioned. If you wrote other code which you think has more accuracy, then that code must have a bug in it.

hi stephen! Thanks for your

ujjwal_kumar @ 31 Oct 2010 06:44 PM

hi stephen! Thanks for your revert. I am using Microsoft Visual Studio 2008: Visual C++ as my compiler. Please suggest me any good compiler on windows. Also, here I found out that standard long double is 15 digits precise only, thats why the confusion: http://msdn.microsoft.com/en-us/library/s3f49ktz%28VS.90%29.aspx

@vivek, I figured out that and corrected it later

That is one of the special

triplem @ 1 Nov 2010 02:50 AM

That is one of the special cases (see http://en.wikipedia.org/wiki/Long_double)

If you want to ensure that you are getting the same results as the judge then you should use the same compiler (gcc-4-0-0-8 or gcc-4-3-2), for which you can find compatible IDEs at http://en.wikipedia.org/wiki/GNU_C_Compiler .

Hey is the current

virai @ 13 Nov 2010 01:50 PM

Hey is the current requirement 6 digits or 9 digits of precision coz in that forum discussion it says only 6 digits required. also could the admin tell me if im failing in 1st k last k or both digits please?

Somebody please tell me why

javadecoder @ 19 Nov 2010 12:30 AM

Somebody please tell me why am I getting a wrong answer for this question!!

Internal Error. Can not

sumitb @ 9 Dec 2010 02:24 PM

Internal Error. Can not submit your answer now. Please try after some time.

why is the judge showing me

vaibhav_pandey @ 19 Dec 2010 04:48 AM

why is the judge showing me wrong answer ? is the internal error still persistent ?

Nope, you are getting wrong

triplem @ 19 Dec 2010 04:56 AM

Nope, you are getting wrong answer because your answer is wrong.

@all what will be the output

jyotigupta2203 @ 26 Dec 2010 04:30 PM

@all

what will be the output of

1 5

is it

00001 00001

or

1 00001

or

1 1

???

The 'Input' section clearly

triplem @ 27 Dec 2010 02:12 AM

The 'Input' section clearly says that test case will not be provided.

n                k 34        

manoharsingh23 @ 19 Jan 2011 12:57 PM

n                k

34              9    :      117566389  909569536

23              8    :       20880467   32910567

92              9    :      466101087  933364736

199            7    :       2963208     3999799

234232       9    :      943982129  347762176

3476566     9    :      226270832  024828416

569999999  9    :      349261536  429999999

999999999  9    :      367879441  999999999

567891234  9    :      191465113  712180736

457474575  9    :      278660968  380859375

@Stephen :can you check

manoharsingh23 @ 19 Jan 2011 01:00 PM

@Stephen :can you check whether above soln are correct or not??

@admin: Where i am doing

dhiman_nikhil @ 19 Jan 2011 06:06 PM

@admin: Where i am doing wrong. http://www.codechef.com/viewsolution/426502.. Unable to verify for larger input.. Getting rite answer as far as  calc supports...

@Manohar - one of your

triplem @ 20 Jan 2011 08:58 AM

@Manohar - one of your results is off by 1. That suggests whatever approach you are using is not precise enough.

@nikhil - you can verify whether your approach will work for larger input. How many digits is log10(n) correct to? When you multiply that by a 9 digit number, how many digits will your number be accurate to? Is that enough?

Is it really so easy

manoharsingh23 @ 24 Jan 2011 08:43 PM

Is it really so easy problem?? Why i am unable to do this even i have done problem of level 4. But no precise idea for this level 1 problem :(..

@admin, I think my Python

thechamp @ 27 Jan 2011 03:25 AM

@admin,

I think my Python code is fast and precise enough to be accepted within time limit but gives TLE.

http://www.codechef.com/viewsolution/435643

what astonishes me more is there are no python AC, all in c/c++ :O

everytime WA dnt know whats

RiteshJethmalani @ 31 Jan 2011 01:20 AM

everytime WA dnt know whats the prob please help!!!!!

 

My code: http://www.codechef.com/viewsolution/439918

does a 0(n) algo work for

iiit @ 25 Feb 2011 11:20 PM

does a 0(n) algo work for this ques

is 4 sec time limit for all

iiit @ 25 Feb 2011 11:22 PM

is 4 sec time limit for all testcases or for each testcase

@all....how can we find the

paarth @ 1 Mar 2011 02:25 AM

@all....how can we find the last k digits....plzz....do reply....

Can anyone tell me where is

paarth @ 2 Mar 2011 01:06 AM

Can anyone tell me where is my code giving WA : http://www.codechef.com/viewsolution/474576

please check the output for

vishal_dhiman @ 11 Mar 2011 12:49 AM

please check the output for n=5 and k=4... if anyone gets a wrong answer please reply here... i was getting an exceptional wrong answer for this input.. is anybody else getting this exceptional case.. only with wrong answers reply.

Hi admin, Can you give me a

anandpdoshi @ 2 May 2011 06:41 PM

Hi admin,

Can you give me a hint on where am I going wrong.

1. Is my algorithm incorrect and I need to think for a different solution or

2. I just need to tweak my algorithm?

Here is my solution: http://www.codechef.com/viewsolution/537865

Please guide.

@admin or anyone who has

anandpdoshi @ 3 May 2011 09:10 PM

@admin or anyone who has solved the problem

please guide where am I going wrong. At the least, please tell me if I am in the wrong direction so that I could stop wasting time. I am getting TLE.

My solution: http://www.codechef.com/viewsolution/539127

Thanks..

Can somebody tell what is the

nakshtra @ 8 May 2011 11:14 AM

Can somebody tell what is the wrong with this result?

11
34 9
23 8
92 9
199 7
234232 9
3476566 9
569999999 9
999999999 9
567891234 9
457474575 9
1000000000 9
117566389 909569536
20880467 32910567
466101087 933364736
2963208 3999799
943982129 347762176
226270832 024828416
349261650 429999999
367880063 999999999
191464928 712180736
278661176 380859375
100000000 000000000

dono y getting WA i made a

dabbcomputers @ 28 Jul 2011 06:23 PM
dono y getting WA i made a brute soln in java using biginteger nd chkd my code for 100 random cases produce same result bt codechef say WA.... :(

is n=0 a valid input for the

sahilgoyal @ 11 Aug 2011 10:45 PM
is n=0 a valid input for the problem even though it is stated 1 ≤ n ≤ 10^9 any suggestions how to check for Huge numbers?

whats wrong in

HARDIK TURAKHIA @ 17 Aug 2011 03:18 PM
whats wrong in http://www.codechef.com/viewsolution/627584.

@admin - Do we require High

bharatj @ 2 Sep 2011 02:44 PM
@admin - Do we require High Precision Arithmetic? better than double?

someone plz provide hint abt

flexicoder @ 8 Oct 2011 08:07 PM
someone plz provide hint abt the least significant digitd

unable to submit solution

rajatkhanduja @ 10 Oct 2011 03:35 AM
unable to submit solution ? Tried C and C++ Says the language is not allowed !!

I am trying to extract the

ajayram @ 9 Apr 2012 05:17 AM
I am trying to extract the first k digits by using the log concept .. However, with this result I am getting correct answer only when n is less than 6 digits: for eg.. n=3476566 and k=9 I get o/P as 226270831 but correct answer is 226270832 for eg n = 999999999 and k=8 I get o/P as 367879529 but correct answer is 367879441 I checked log(n) in both cases and I am getting only 6 decimal places, even if I use long double, Could someone tell me of a way to increase the precision here ? I am clueless about how to extract the last k digits..!!! Currently, last k digits is working only for small n

is this just level 1 problem?

pranalee @ 3 Jun 2012 07:33 PM
is this just level 1 problem? m speechless

How to get past through this

nhooda @ 21 Jun 2012 12:57 AM
How to get past through this Time limit? I mean is there any software which tells you exact compile time???

Can anyone tell me why below

jimit_it @ 3 Jul 2012 11:30 AM
Can anyone tell me why below code is wrong for above problem? I have written code in PHP. ==================================================================================================================== //Suppose below are my posted array $nTimeMul = array(4,9); $nToAppear = array(2,3); function getDezireOutput($nTimeMul = array(), $nToAppear = array()) { $i = 0; foreach ($nTimeMul as $num) { $tempNum = 1; for ($t=0; $t < $num; $t++) { $tempNum = $tempNum * $num; } echo substr ($tempNum, 0, $nToAppear[$i]).' '.substr ($tempNum, -$nToAppear[$i])."nn"; $i++; } } getDezireOutput ($nTimeMul, $nToAppear);

@Admin... I have tested my

vicky239 @ 7 Jul 2012 07:50 PM
@Admin... I have tested my program many times and with many different cases and each time checked answers on wolframalpha..... but still it is showing here as WA.. can u check the below solution http://www.codechef.com/viewsolution/1165304 n also can you part of data for each we r getting error.... this will help us a lot.... I am also pasting the output which i am getting.... 4 999999999 9 1000000000 9 1234 1 1546 4 367880063 999999999 100000000 000000000 4 6 3295 5696

Admin pls help, why am I

pankajb64 @ 8 Jul 2012 08:35 PM
Admin pls help, why am I getting a RunTime Error here when my code runs fine on my machine ? It shows NZEC but I cant understand what is causing that.

@admin please give a hint

arihanty @ 13 Jul 2012 12:56 PM
@admin please give a hint where i could be wrong .Because all testcases i have tried give me right answer.here is my solution http://www.codechef.com/viewsolution/1178215

hi admin My answer has been

tarun483 @ 25 Aug 2012 03:05 PM
hi admin My answer has been judged as WRONG. on all numbers I tested it, it generated the correct answer!! I made it in PHP....does it has something to do with it?? Or my program is really wrong??

anyone pls i need some

madhavan @ 25 Aug 2012 10:24 PM
anyone pls i need some help.... my code runs fine n gives correct output till the no is less than 14 .. above that my calculator gives me a different ans n the program gives me a different one... i m using java language n using Math.pow() method... i dont understand what to do next ...thanks for ur time..

@tarun483 if ur program gives

madhavan @ 25 Aug 2012 10:29 PM
@tarun483 if ur program gives a wrong ans pls check the FAQ on php thing.. u might need to change name of file or insert a blank line.. read FAQ for more details..

I am unable to use cin & cout

suryadharani @ 20 Oct 2012 08:02 PM
I am unable to use cin & cout to take input and give out the output. I mean it during the submission.. [ prog.cpp:14: error: 'cin' was not declared in this scope prog.cpp:47: error: 'cout' was not declared in this scope ] What am i supposed to do, ?

@suryadharani using namespce

rpsr15 @ 22 Oct 2012 10:46 AM
@suryadharani using namespce std;

not able to submit this

vkygarg @ 27 Dec 2012 10:39 AM
not able to submit this question tell help me out...as soon as i click on submit something goes wrong...!!

@admin. is a solution

sumandas337 @ 19 Feb 2013 07:53 PM
@admin. is a solution possible in java.. the log10 function in java is returning different values for case k=9. from c compilers . i tried 4 ,6,8 precision using DecimalFormat but my answer is still not getting accepted. Please help

http://www.codechef.com/views

sumandas337 @ 19 Feb 2013 07:54 PM
http://www.codechef.com/viewsolution/1831870. link to my code

#include #include int

neerajp2109 @ 14 Apr 2013 04:27 PM
#include #include int main() { int t; long int i; scanf("%d",&t); for(i=0;i

admin pls tell what is error

neerajp2109 @ 14 Apr 2013 04:27 PM
admin pls tell what is error in dis code

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

HELP



Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

  • If you are still having problems, see a sample solution here.
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.