• 2017 ACM/ICPC Asia Regional Qingdao Online


    2017-09-17 17:12:11

    writer:pprp

    找规律,质数只有是两个相邻的立方数的差才能形成,公式就是3 * n * (n + 1) +1, 判断读入的数是不是满足

    这次依然只是做了两道签到题,其他题做了,但是因为没有想到好的算法,所以没有通过,唯一值得高兴的是这两个都是我自己做的

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    
    using namespace std;
    typedef long long ll;
    const ll maxn = 1e12 + 1000;
    ll x,y;
    
    int main()
    {
       ios::sync_with_stdio(false);
        freopen("in.txt","r",stdin);
        int cas;
        cin >> cas;
        while(cas--)
        {
            bool tag = 0;
            cin >> x;
            if((x - 1) % 3 == 0)
            {
                ll pprp = (x-1)/3;
                ll tmp = sqrt(pprp);
                for(ll i = 1 ; i <= tmp ; i++)
                {
                    if(i * i + i == pprp)
                    {
                        tag = 1;
                        break;
                    }
                }
            }
            if(tag == 0)
                cout << "NO" << endl;
            else
                cout << "YES" << endl;
    
        }
        return 0;
    }
  • 相关阅读:
    MQ
    redis
    MongoDB
    进程相关命令
    catalina.sh
    tomcat-jvm
    中间件简介
    websphere
    mysql
    shell变量与字符串操作
  • 原文地址:https://www.cnblogs.com/pprp/p/7536329.html
Copyright © 2020-2023  润新知