hdu 5878

讨论

水题,事先打好表,发现只有不到5200个不同的数,然后二分就可以了
怎么打表?写个四重循环,反正在本地跑,多跑一会也无所谓
所以下面给的代码不是提交的代码(5194个数,一点都不好看),而是生成的代码
其实生成代码里的另一部分是用另外一个代码生成的,那个就太好想了
然而比赛没想到……

题解状态

624MS,1432K,44328 B,G++

题解代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 200000
#define memset0(a) memset(a,0,sizeof(a))

#define long long long 
int pow2[] = { 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912 };
int pow3[] = { 1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489 };
int pow5[] = { 1,5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625 };
int pow7[] = { 1,7,49,343,2401,16807,117649,823543,5764801,40353607,282475249 };
set<int>a;
void fun()
{
    for (int p = 0; p <= 29; p++)
        for (int o = 0; o <= 18; o++) {
            if ((long)pow2[p] * pow3[o] > 1000000000)
                break;
            for (int i = 0; i <= 12; i++) {
                if ((long)pow2[p] * pow3[o] * pow5[i] > 1000000000)
                    break;
                for (int u = 0; u <= 10; u++) {
                    if ((long)pow2[p] * pow3[o] * pow5[i] * pow7[u] > 1000000000)
                        break;
                    a.insert(pow2[p] * pow3[o] * pow5[i] * pow7[u]);
                }
            }
        }
    for (int x : a)
        printf("%d,", x);//output
}
int main(void)
{
    //freopen("vs_cin.txt", "r", stdin);
    freopen("vs_cout.txt", "w", stdout);

    fun();
}

EOF

展开阅读全文
©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值