Book pages

The problem description is here: http://www.mcs.vuw.ac.nz/~david/acm/P2_Pages.pdf
The code I have outputs the correct number of pages for most small digits, but when I get to 1999999998, it outputs a negative number and nowhere in the code can I find out why. Was wondering if anyone had a better solution.
import java.lang.*;
public class Test {
static int count = 0;
static int count2 = 1;
static int num_pages = 0;
static int argument;
public static int getDigits(int n) // returns the number of digits in n
{  ++count;
  return (n / 10) < 1 ? count : getDigits(n / 10);
public static void compute(int digits)
{ double i = 0.0; double j = 1.0;
boolean h = true;
    while (h) {
double low = Math.pow(10.0, i++);
double high = Math.pow(10.0, j++);
int x = (int) (high - low);
int total_digits = x * count2;
if (argument <= total_digits && (argument % count2 == 0)) { num_pages += argument / count2;
h = false;}
else if (argument <= total_digits && (argument % count2 != 0)) { System.out.println("Impossible");
h = false;}
else { argument -= total_digits; num_pages += x; }
   ++count2; }
public static void main(String[] args) {
int p = Integer.parseInt(args[0]);
argument = p;
int c = getDigits(p);
compute(c);
System.out.println("For " + p + " digits " + "there are " + num_pages + " pages");
          }

I'm sure there is a mathematical expression whereby it just takes one line to solve this, but I can't quite see that. What I can see is that you're complicating things far too much.
    private static int compute(int digits) {
        int length = 0;
        int page = 0;
        int numDigits = 1;
        int increaseAt = 10;
        while(true) {
            page++;
            if(page >= increaseAt) { numDigits++; increaseAt*=10; }
            length += numDigits;
            if(length == digits) return page;
            if(length > digits) return -1; // Impossible!
    }

Similar Messages

  • When I choose a photo to share on face book a drop down box appears with the message, Face book didn't recognise the information you entered for the account this is my Face book login information I use to access my face book page how can I overcome the b

    when I choose a photo to share on face book a drop down box appears with the message, Face book didn't recognise the information you entered for the account this is my Face book login information I use to access my face book page how can I overcome this.

    Delete abd re-enter your Facebook account information jnder the accounts tab in the iPhoto preferences
    You may also want to take a look at the user tip for Facebook problems
    LN

  • Doesn't open the PDF file (i.e. articles, books pages). It appears a black page. Thanks for help

    Safari doesn't open the PDF file (articles, book page, etc). It appears a black page. Before that it was working perfectly. Thank for your help

    Try this ...
    Open a Finder window then from the menu bar click Go > Go to Folder
    Type or copy paste the following:
    /Library/Internet Plug-Ins
    Click Go.
    If you see the:  AdobePDFViewer plugin (or anything Adobe related) in the Internet Plug-Ins folder, move it to the trash.
    Restart your Mac and try opening a PDF file.

  • Many times I drop a photo into a book page box and it resizes it.  I want to scale it smaller but it only allows me to make it bigger.  Why can't I slide to make it smaller?

    many times I drop a photo into a book page box and it resizes it.  I want to scale it smaller but it only allows me to make it bigger.  Why can't I slide to make it smaller?

    Control (right) - click on the photo in the frame and select Fit to Frame Size in the contextual menu.
    Here's an extreme example of that:
    OT

  • Ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    No on the book title, no problem there.
    The issue is: my book pages appear as on white paper, no background that resembles a open book and also no option to change fonts. The book was created in iBooks author, there was a problem going with the "Publish" menu route so I was instructed my Apple to "export" the file and submit that. I think that's the problem after reading that iBooks author is a hybrid epub file.
    Thanks for getting back to me.

  • Swirling images on a book page

    I somehow got an image to move in a circle and I can't figure out how to replicate it so I can swivel other images to sit at an angle as well. Anyone know how. I check to entire manual and came up with no answer.

    Go into the book within Aperture. In the button bar just above the book pages and the book preview window you will see a Theme Button, an Edit Content Button, and an Edit Layout Button (from very left moving to the right). Click on the Edit Content Button.
    Move the mouse down to the image you want to rotate on the book page. Single click on the image (or the image placeholder if there is no image there). The image (or placeholder) will be surrounded with little boxes in each corner and along each edge. Move the cursor to one of the boxes in the corner until the cursor turns into a plus.
    Now, click, hold, and drag the cursor to rotate. Let go and you are finished. Click on the Edit Content Button to be able to drag pictures into the book again.
    Message was edited by: ifarlow

  • Photos don't display on book pages after upgrading to 9.4.2

    I have several books I created in version 9.4.1. After upgrading to iPhoto 9.4.2, most of the pictures will not display on the book pages. Only 1 photo displays out of 3 or 4 photos on the page. Is there a setting that has changed? Using Mountain Lion 10.8.2 on MacBookPro10,1

    Did you duplicate the existing book or create a new empty book and add the same photos?
    Have you tried rebuilding your library as follows: make a temporary, backup copy of your library if you don't already have one (Control-click on the library and select Duplicate from the contextual menu) and  apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Since only one option can be run at a time start with Option #1, followed by #3 and then #4 as needed.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments.  However, books, calendars, cards and slideshows will be lost. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.

  • How to copy and paste text from one photo book page to another.

    hello,i downloaded this software 2days ago,and i've been having so much fun with it. pls i need help on how to copy and paste text from one photo book page to another. Secondly how to copy my completed photo book pages project to another laptop for printing. thanks
    This question was solved.
    View Solution.

    Hi DG.
    The easiest way to copy an HP Photo Creations project to another computer is to click the Share button. That will upload the project to the Web and give you a link you can paste into an email. Clicking the link on the other computer allows you to download the project and personalize it. This quick video shows the process. (The screen looks slightly different now, but the concept is the same.)
    Another way to share a project is copy the project folder to a thumb drive. Look in Documents/HP Photo Creations/My Things to find your saved projects.
    Our customer support team would be happy to walk you through the process. Contact them at [email protected]
    Hope this helps,
    RocketLife 
    RocketLife, developer of HP Photo Creations
    » Visit the HP Photo Creations Facebook page — news, tips, and inspiration
    » See the HP Photo Creations video tours — cool tips in under 2 minutes
    » Contact Customer Support — get answers from the experts

  • Adobe products recommend to make comic book pages?

    I am a graphic novel writer & comic designer.
    I have been told that many of Adobe's products can be used
    to create drafts for comic book pages. But some people tell me
    Illustrator is the best, others say In Design is the way to go and
    I have even heard Photoshop works as well. I guess I am just
    look for some advice from a Adobe expert. What Adobe product would you recommend to use for making comic book pages?

    Photoshop for line cleanup, inking, flats and coloring, and a few people use it for text.
    Illustrator for creating text boxes and lettering, and some people use it for layout.
    InDesign for layout and publishing, and some people use it for text effects as well.

  • How to hide/show book, page, portlet programmatically

    Hello,
    The situation is I have few books and have pages within the books. In page, I have few portlets. The problem I try to solve is when user login, based on user role, I selectively show the books, pages and portlets.
    Can anyone give guideline on this ?
    Thanks in advance,
    Li

    "Chris Xu" <[email protected]> wrote in message
    news:8877896.1094662465884.JavaMail.root@jserv5...
    The situation is I have few books and have pages within the books. Inpage,
    I have few portlets. The problem I try to solve is when user login, basedon
    user role, I selectively show the books, pages and portlets.
    Can anyone give guideline on this ?Use entitlements for this, see
    http://e-docs.bea.com/wlp/docs81/adminportal/help/VE_OV.html
    Gerald

  • ADDRESS BOOK & PAGES

    I want to use my address book list of contacts for making a Merge address book cards in a Pages document.
    It does do the merge, but they do not appear in Alphabetical Order. When using Address Book on its own they do so. The printer is set to print in that mode.
    Any ideas please.

    Hi:
    I'm familiar with this feature. The pocket address book pages are intended to be printed on standard size paper, and then the printout will have tiny guide-lines at the page corners where you should cut with scissors. When all the pages are cut, they can be arranged in alphabetical order and will provide a staggered thumb-flip along one side. The pages should be stapled together on the right side. Feel free to reply if you have more questions.

  • How to view iPhoto book pages full screen

    I have made a book in the latest version of Aperture. Now I want to view the pages of my book in full screen view - the book, not the individual pics. It would be great if I could make the book pages into a slideshow too. I can't work it out - HELP!!!

    Welcome to the forum.
    It's a bit of round robin, but you can make it a slide show. Go to File >> Print Book. In the print dialog click the PDF button in the lower left corner and choose "Save PDF to Aperture". This will bring up the import PDF Import dialog. Choose either Tiff or JPEG, and either chose a project or create a new one to save it in. Voila! You now have images of the pages to make a slideshow with. You still may want to crop the borders off the pages.
    DLS
    !http://dlsphoto.com/a3pdfImport.jpg!
    Message was edited by: DLScreative
    Message was edited by: DLScreative

  • Can't add text to book pages

    I just installed Aperture 2.1.2 and am trying to add a text box over an image on a book page. On the actions bar the only buttons that work after selecting the image are the Set Photo Filter and Set Background. The buttons for Text Style, Metadata Format, Add Text box, Add Metadata, Add Photo, Send Backwards and Send Forward are "grayed out" Also, if I try to select Add Text from the Book Actions button at the bottom of the Book pane, all of the options from the Add selection are grayed out. I am able to select and resize an image (I get yellow box around it). What do I need to do to enable these actions? The Aperture Manual just say's to use the Add Text tool, but it's not active on my system.
    I am able to edit text on pages thet have pre-formatted text items.

    Have the same problem and wondering if you ever found out how to make the Content and Layout buttons visible. Strangely these buttons are there if I use Aperture on my PowerBook, but not and my desktop Mac. Drives me crazy because I need to add more text and captions to some book pages.
    Thomas

  • I have a stikie note in the middle of my book page (library) and I cant take it away. help!

    I have a stikie note in the middle of my book page (library) and I cant take it away. help!

    Try a Reset [Hold the Home and Sleep/Wake buttons down together for 10 seconds or so (until the Apple logo appears) and then release. The screen will go blank and then power ON again in the normal way.] It is app and data safe

  • Splitting dual book pages into separate pdf pages

    I have a book scanned into pdf with two book pages per adobe page (side by side). How can I split the pdf page in way that each book page becomes its own pdf page? My chief concern is that one side is always tilted which makes reading and highlighting difficult. Any help would be great. I have Acrobat 9 pro on vista. thanks.

    I have had to do this in the past, but the problem is the file size then
    doubles. I haven't figured out an easy to way to remove the data from the
    cropped areas.

  • Enlarging book pages to make proofreading captions easier

    Is there a way to zoom pages of a book to a larger size when proofing so that small font sizes can be more easily read? I find that font size below 12 is difficult when checking for spelling, etc., and I was wondering if there is a way i haven't discovered to temporarily increase the size of book pages for proofreading. Thanks.

    Before you order it is recommended that you preview your order - http://support.apple.com/kb/HT1040 - and save the PDF in case of issues - and the PDF can be viewed in zoomed mode with preview or Adobe reader
    LN

Maybe you are looking for

  • "the item you selected is not available in the uk"

    I can't access the iTunes store even though I am in the UK. it's a new computer with the latest version of iTunes downloaded and running away fine but this is killing me. any help appreciated, been through all the help topic and they come up against

  • It's easy to do but why it doesn't works??

    Please help me guys, i'm not able to solve my problem,i'm trying and trying. I've downloaded from http://java.sun.com/products/plugin/1.5.0/demos/plugin/applets.html an applet demo,the clock. i've tested it with this simple html file <html> <head> <t

  • Can someone clear this up for me.

    I have been hearing around the forums that on the package 40/10 if you didnt recieve 37.5 or above download upgrading to the new 80/20 package is pointless ?

  • Installing Security and Compliance Manager on Windows 8.1

    Hi I am trying to install Security and Compliance Manager on my Windows 8.1 workstation.  The install is trying to install SQL Express 2008 which seems to not be compatible with Windows 8.1 and that is were the install ends. I tried installing SQL Ex

  • Test topic for duke dollars test case

    Have had issues reported regarding not being able to assign duke dollars. This is a test to see if there's an issue or not. -- DanG