码迷,mamicode.com
首页 > 其他好文 > 详细

2017 ACM/ICPC Asia Regional Qingdao Online - 1011 A Cubic number and A Cubic Number

时间:2017-09-17 18:52:07      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:lin   and   while   div   turn   return   const   writer   number   

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;
}

 

2017 ACM/ICPC Asia Regional Qingdao Online - 1011 A Cubic number and A Cubic Number

标签:lin   and   while   div   turn   return   const   writer   number   

原文地址:http://www.cnblogs.com/pprp/p/7536329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!