zoukankan      html  css  js  c++  java
  • loj6221. 幂数!

    题意

    求出(N(N leq {10}^ {11}))以内的幂数的个数及和。
    幂数满足其所有质因数都至少有两个。

    题解

    不说了,又斯波了。
    两个性质:
    1.答案较小
    2.幂数一定是(a ^ 2 b ^ 3)的形式

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e6 + 1;
    ll n, ans1, ans2, a[N], b[N];
    vector <ll> c;
    bool sqrfree (ll x) {
    	ll s = sqrtl(x + 0.5);
    	return s * s != x;
    }
    int main () {
    	cin >> n;
    	a[0] = a[1] = 1;
    	for (int i = 2; 1ll * i * i <= n; ++i) {
    		a[++a[0]] = 1ll * i * i;
    	}
    	b[0] = b[1] = 1;
    	for (int i = 2; 1ll * i * i * i <= n; ++i) {
    		if (sqrfree(1ll * i * i * i)) {
    			b[++b[0]] = 1ll * i * i * i;
    		}
    	}
    	for (int i = 1; i <= a[0]; ++i) {
    		for (int j = 1; j <= b[0] && a[i] * b[j] <= n; ++j) {
    			c.emplace_back(a[i] * b[j]);
    		}
    	}
    	sort(c.begin(), c.end());
    	n = unique(c.begin(), c.end()) - c.begin();
    	for (int i = 0; i < n; ++i) {
    		++ans1;
    		ans2 += c[i];
    	}
    	cout << ans1 << endl;
    	cout << ans2 << endl;
    	return 0;
    }
    
  • 相关阅读:
    用导数解决逗逼初三数学二次函数图像题
    NOIP 2014 pj & tg
    BZOJ 1004
    双参数Bellman-ford带队列优化类似于背包问题的递推
    emu1
    無題
    15 day 1代碼
    javascript quine
    线段树的总结
    Watering the Fields(irrigation)
  • 原文地址:https://www.cnblogs.com/psimonw/p/11246293.html
Copyright © 2011-2022 走看看