LOGIN
  • Register
  • Forgot Password?

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • March Algorithm Challenge
    • February Algorithm Challenge
    • January Algorithm Challenge
    • December Algorithm Challenge
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • About Directi
    • Careers
Home » Problems (medium) » Money Matters

Money Matters

Problem code: MONEY

  • Submit
  • All Submissions

The Government of Byteland has decide to issue new currency notes with special protection features to commemorate a great mathematician.

It has decided to issue notes summing up to N such that all the sums from 1 to N should be possible to be made by selecting some of the notes. Also this has to be done in way such that if any note from 1 to N can be made in more than one way by combining other selected notes then that set of notes is not valid.

For example, with N = 7,

The valid sets are:
{1,1,1,1,1,1,1}
{1,1,1,4}
{1,2,2,2}
{1,2,4}

Invalid sets are:
{1,1,1,2,2} beacuse the sum adds up to 7 but 2 can be made by {1,1} and {2}, 3 can be made by {1,1,1} and {1,2}, 4 can be made by {1,1,2} and {2,2} and similarly 5, 6 and 7 can also be made in multiple ways using the same set.
{1,1,3,6} beacuse all from 1 to 7 can be uniquely made but the sum is not 7 (its 11).

Before implementing this idea of issuing these new set of notes, the Government wants to know how many possible valid sets are there for a given N. Your program should help the Government to find this out.

Input

First line will contain the number of test cases T (1<=T<=6666).
Each test case will have one line containing an integer N (<= 2^31-1).

Output

For each value of N output the total number of valid sets on a separate line.

Example

Input:
3
7
111212121
1000

Output:
4
75
13

Date: 2010-01-26
Time limit: s
Source limit: 50000
Languages:


  • Submit

Comments

  • Login or Register to post a comment.

The problem statement is

Balajiganapathi - 27th Jan,2010 16:03:02.

The problem statement is incomplete

@Balajiganapathi: Can u pls

Anirban Mitra - 27th Jan,2010 22:38:46.

@Balajiganapathi: Can u pls explain how

sorry.........my browser did

Balajiganapathi - 28th Jan,2010 12:09:49.

sorry.........my browser did not display the problem properly.........

the output section was not visible

now i can see it

what is the time limit for

Abhishek Goyal - 31st Jan,2010 11:38:36.

what is the time limit for the problem !???

I have the correct logic, but

Rajat Tibrewal - 3rd Feb,2010 13:56:25.

I have the correct logic, but the upper limit of N is a problem. Either memoization fails because array size is too big (even if I use short int) or time limits exceed if non-memoized. Any suggestions?

If the upper limit of N is a

Stephen Merriman - 3rd Feb,2010 14:26:27.

If the upper limit of N is a problem then obviously you do not have the right logic :P So you'll need to think of a brand new approach to the problem.

my solution is correct and

Jaideep - 9th Feb,2010 13:00:26.

my solution is correct and also work for upper limit.. i have not used array..

in my system i get result. but in this site it takes times to execute. i get Time Limit Exceeded error..

Therefore your solution is

Stephen Merriman - 9th Feb,2010 13:40:32.

Therefore your solution is not correct. You'll need to program something that works faster.

what is the max value it

Jaideep - 9th Feb,2010 16:53:52.

what is the max value it should accept??

how much time has been

Jaideep - 9th Feb,2010 17:30:41.

how much time has been alloted for execution of extreme test case 2147483647..

printing 6666 test cases is

Jaideep - 11th Feb,2010 11:27:03.

printing 6666 test cases is taking time..

i am solving highest poosbile values in less then second but printing result is taking time

Any one can explain for N =

Uday - 12th Feb,2010 12:38:46.

Any one can explain for N = 11......

why {1,6} is invalid when

RameshKumar V - 12th Feb,2010 13:18:17.

why {1,6} is invalid when N=7?

Because that clearly doesn't

Stephen Merriman - 12th Feb,2010 13:20:01.

Because that clearly doesn't let you have all sums from 1 to 7.

@Stephen, thanks mate...  i

RameshKumar V - 12th Feb,2010 13:25:54.

@Stephen, thanks mate...  i got it.. i shoud have read the problem carefully... :(

can i post C#3.0 solution to

RameshKumar V - 12th Feb,2010 13:27:31.

can i post C#3.0 solution to this one.. because when i registered it only shows up C#1.0 & C#2.0 in laguage choice...

I am getting wrong answer

Sunny Jain - 14th Feb,2010 16:55:52.

I am getting wrong answer when i submit my solution. Can I know for what value is the algorithm failing ? As i have tried manually, for few small input values and it seems to give correct answer. And also, one of my solution gives a time limit exceeded error, is that mean that the answer returned by that code is correct?

i got what was wrong with my

Sunny Jain - 15th Feb,2010 20:59:33.

i got what was wrong with my code... Now again back to time limit exceeded... :(

I am still getting Time

Sunny Jain - 19th Feb,2010 00:37:49.

I am still getting Time Limit Exceeded error, even after optimizing my algorithm. I have tested it on my machine for 1000 inputs, and it solves them in 3minutes, which averages each output time to within 1sec. Though for one of the input - "1492192799" which has answer of "748543104", it took around 2 sec (which must be because of large output value), the other outputs were returned/printed within 1sec of time.

Your code must complete the

Stephen Merriman - 19th Feb,2010 02:00:02.

Your code must complete the entire input file (ie possibly 6666 test cases) in 1 second total. FAQ

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

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.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
Sponsors
The time now is: