[Water + math] Fzu OJ 2193 so hard and 2191 perfect numbers

Source: Internet
Author: User
Tags cmath

2193 so hard

Test instructions

Simplify decimals.

Ideas:

No more than 9 bits, then multiply 10^9 just fine.

Then note that the accuracy is added.

Code:

#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include " iostream "#include" map "#define LL __int64#define eps 1e-11using namespace std;ll gcd (ll a,ll b) {    return b==0?a:gcd (b, A%B);} int main () {    int t;    cin>>t;    while (t--)    {        double x;        scanf ("%lf", &x);        ll fz= (LL) ((x+eps) *1000000000);        ll fm=1000000000;        ll TEP=GCD (FZ,FM);        printf ("%i64d/%i64d\n", Fz/tep,fm/tep);    }    return 0;}

2191 the perfect number

Test instructions

The perfect degree of each number within the [a, b] interval.

The so-called perfect degree is the number of a*a*b (0<A<=B) that x can break down into.

Ideas:

Within the [1,x] interval.

We enumerate A.

Because a<=b for each I, so to set up, the smallest number is I*i*i

However, we just have to judge how many i*i are in the range of i*i*i<=x.

For each i*i-i+1.

Then subtract.

Code:

#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include " iostream "#include" map "#define LL __int64#define EPS 1e-11using namespace std;int main () {    ll x, y;    while (scanf ("%i64d%i64d", &x,&y)!=-1)    {        ll ansx=0,ansy=0;        x--;        for (ll i=1;i*i*i<=x;i++) ansx+=x/(i*i)-i+1;        for (ll i=1;i*i*i<=y;i++) ansy+=y/(i*i)-i+1;        printf ("%i64d\n", ANSY-ANSX);    }    return 0;}




[Water + math] Fzu OJ 2193 so hard and 2191 perfect numbers

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.