POJ 3175--Conditional Enumeration

Source: Internet
Author: User

Test instructions

Give a number n, and then give the number of N, indicating the number of decimal places, the number of digits after the root of the numbers is this n number, to find the most decimal place to meet such conditions.


Input:

3
123
Output:

17

Analysis:

If x.123 ... If the square of this number is an integer, it must


SQR (x.124) > Ceil (SQR (x.123)) [SQR = squared, Ceil = rounding up]

So, it is possible to enumerate its integer part X from small to large, and encounter the first x that satisfies the result, which is the answer.


Code:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

Long long l,n;
Double a[]={1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9};
int main ()
{
    scanf ("%i64d%i64d", &l,&n);
    Double x=n*a[l];
    For (long long i=1;; i++)
    {
        double p=x+i;
        Double c= (P+a[l]) * (P+a[l]);
        Double b= (Long Long) (p*p) +1;
        if (c>b)
        {
            printf ("%i64d\n", (Long Long) b);
            break;
        }    
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.