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 Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » July 2010 » Rearranging Digits

Rearranging Digits

Problem code: ARRANGE2

  • All Submissions

All submissions for this problem are available.

A number X is called Permut number if X and 2X ( both without leading zeroes ) have same number of digits and are permutations of each other. Given A and B, find the number of Permut numbers >= A and <= B.

Note : X is called permutation of Y if every digit ( 0 - 9 ) occurs same number of times in both the numbers ( maybe at different positions ).

Input :

The first line contains the number of test cases T. T lines follow, containing two integers A and B.

Output :

Output T lines, one for each test case containing the desired answer for the corresponding test case.

Sample Input :
2
1 100
499875921 499875921

Sample Output :
0
1

Constraints :
1 <= T <= 10000
1 <= A <= B <= 10000000000 (10^10)

Author: syco
Date Added: 5-05-2010
Time Limit: 1 sec
Source Limit: 5000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

how are 1 and 100 permut

ishandutta2007 @ 2 Jul 2010 02:06 AM

how are 1 and 100 permut numbers?

read the statement carefully.

nokia @ 2 Jul 2010 02:28 AM

read the statement carefully.

499875921  499875921 how is

narutouzumaki2 @ 3 Jul 2010 01:30 AM

499875921  499875921

how is it possible to have a permut number between two equal numbers

if x is 499875921 then 2x=999751842 is out of the range

 

how is this possible

 

 

@ Naruto   read the statement

root5 @ 3 Jul 2010 02:06 AM

@ Naruto

 

read the statement carefully.

 

"Given A and B, find the number of Permut numbers >= A and <= B."

The problem is to calculate

rizwanhudda @ 3 Jul 2010 02:34 AM

The problem is to calculate the number of permute numbers between A and B "Inclusive of A and B"

and X has to be in that range. 2*X need not be in that range, If you read the definition carefully you will realise taht.

what us unit of source limit?

nitin.nizhawan @ 3 Jul 2010 06:11 AM

what us unit of source limit? bytes, loc, kloc, or KB?

btw ... 999751842 IS in

f03nix @ 3 Jul 2010 06:22 AM

btw ... 999751842 IS in range. (range is 10^10 ... greater than what a normal int can hold)

"Your solution is too long

cgy4ever @ 3 Jul 2010 05:32 PM

"Your solution is too long for this problem, the limit is 5000 bytes!"

My program is about 6K , don't save any calculated data.

What a pity!

i got time limit exceeded,

dwrakh @ 4 Jul 2010 12:38 PM

i got time limit exceeded, does that mean that my code worked correctly too much time ??

Condition for permutation

atullala @ 4 Jul 2010 12:41 PM

Condition for permutation should be checked including leading zeros or excluding leading zeros ........?

@karthik time limit exceeded

ritesh104 @ 4 Jul 2010 01:41 PM

@karthik

time limit exceeded doesn't mean ur code worked correctly.

Have you browsed through the FAQ ?

@Atul  read the first line carefully

hey i am using java n i am

sumeet666 @ 4 Jul 2010 02:57 PM

hey i am using java n i am getting the same compilation error every time that the main function does not exist when it does..i have checked it a hundred times..i am not getting how to remove this error..can someone help me..

@sumeet : check if you have

dwrakh @ 4 Jul 2010 03:01 PM

@sumeet : check if you have used any package in your program, if yes remove the package, you wont get the compilation error. The error you are getting now is because your main() is not visible to the compiler.

is the time limit given here

dwrakh @ 4 Jul 2010 10:07 PM

is the time limit given here is for compilation or execution?

@Karteek its for execution

anshusaurav @ 4 Jul 2010 10:43 PM

@Karteek its for execution

No one is able to submit it

sakul123 @ 4 Jul 2010 11:08 PM

No one is able to submit it in java.

 

@ admin, is there anything wrong...does java also has time limit of 1s ???????????

@sumeet and all other JAVA

tourniquet_grab @ 5 Jul 2010 04:14 PM

@sumeet and all other JAVA users. NAME YOUR PROGRAM AS "Main".

Name is 'Main' only.

sakul123 @ 5 Jul 2010 05:51 PM

Name is 'Main' only.

Java has a time limit of 2

schampiri @ 6 Jul 2010 02:35 PM

Java has a time limit of 2 seconds.

Finally!!! Got thru the time

shettynamit @ 8 Jul 2010 01:48 PM

Finally!!! Got thru the time limit :D

Why am I getting compilation

akhilesh890 @ 9 Jul 2010 03:08 PM

Why am I getting compilation error full of a page when I submit?It work fine in my computer.Something's screwed up.

FAQ

triplem @ 9 Jul 2010 03:15 PM

FAQ

Time limit is too strict , my

mcsharma1990 @ 9 Jul 2010 09:18 PM

Time limit is too strict , my program is running in 1.2 sec for 10000 cases :(

 

phew.. got ACpted finally.

mcsharma1990 @ 10 Jul 2010 02:49 AM

phew.. got ACpted finally.

please post the

dabbcomputers @ 11 Jul 2010 08:44 PM

please post the editorials....

I submitted different

Juned123 @ 11 Jul 2010 09:10 PM

I submitted different solutions to this problem atleast 100 times but every time I got TLE.

My program in C took 0.9s for the test case 1 10000000(ie. 10^7).

How can I get my program to work under 1s for the test case 1 10^10(ie. the worst case)?

Can anyone plz help.

eagerly waiting for the

akantev @ 11 Jul 2010 11:50 PM

eagerly waiting for the editorials.... in the meanwhile itd be very nice if someone could give some hints about this problem..

you can pre-generate all the

mcsharma1990 @ 12 Jul 2010 02:03 AM

you can pre-generate all the possible numbers between 1 - 10^10 using optimized brute force (450972 all possible numbers) then use binary search for each test case to find number of entries between a given range....this gave me TLE many times but with different optimizations I finally managed to get it AC. :).

the time limit 4 this problem

shettynamit @ 12 Jul 2010 03:21 PM

the time limit 4 this problem was very harsh ... my 1st implementation was using stl set to store the pre-generated permut numbers .... that timed out.... finally had to resort to plain old arrays,quicksort and binary search :)

^ for me even that failed , i

f03nix @ 17 Jul 2010 02:17 PM

^ for me even that failed , i must've been using wrong way to move through the permutations.

Since the contest editorial doesn't seem to say anything about that , i wonder what permutation technique should we have used once we knew the digits we want to permute.

here's the closest i could get to a solution : http://pastebin.com/tL2UT0w9

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
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.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com