HDU 5778 ABS (Prime, violence)

Source: Internet
Author: User

Test instructions: Given a number x, the positive integer y≥2y\geq 2y≥2, so that the following conditions are met: 1.y-x the absolute value of the minimum 2.y of the mass-factor decomposition of each factorization is exactly 2 times.

Analysis: Because each factorization in the decomposition of Y-factor is 2 times, then Y is a complete square number, set Y=z*z, the title can be converted into Z, so that each factorization appears 1 times. We can violently enumerate Z, check if z meets the requirements,

Obviously, when Z is a prime number that is compliant, the enumerator of Z is available by the prime numbers theorem, the Logn level complexity O (n4logn2\sqrt[4]{n}log\sqrt[2]{n}.

Pay attention to y>=2.

The code is as follows:

#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype>using namespace std; typedef long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e5 + 5;const int D R[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 &&amp ; R < n && C >= 0 && C < m;}    inline bool Solve (LL x) {int n = (int) sqrt (x+0.5);        for (int i = 2; I <= n; ++i) if (x% i = = 0) {x/= i;    if (x% i = = 0) return true; } return false;}    int main () {//Ios::sync_with_stdio (FALSE);  int T, q;    Cin >> T;        while (t--) {LL x;        CIN >> X;        ll T1 = (ll) sqrt (x*1.0); LL t2 = t1+1;        while (T1 > 1 && Solve (t1))--t1;        while (Solve (T2)) ++t2;        LL ans = ABS (t2*t2-x);        if (T1 >= 2) ans = min (ans, ABS (t1*t1-x));    cout << ans << endl; } return 0;}

?4??√?N???LOG2 √< Span class= "Vlist" >? n? ?? )

HDU 5778 ABS (Prime, violence)

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.