题解 | A - GCD

GCD

https://ac.nowcoder.com/acm/contest/7607/A

考虑数的唯一分解

f(px)=p,f(pixi)=1f(p^x) = p, f(\prod p_i^{x_i}) = 1
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 1e7 + 10, M = 2e6 + 10, inf = 0x3f3f3f3f;

inline int read() {
    bool sym = 0; int res = 0; char ch = getchar();
    while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) res = (res &lt;&lt; 3) + (res &lt;&lt; 1) + (ch ^ 48), ch = getchar();
    return sym ? -res : res;
}

bool flag[N];

int n, m, cnt, prime[N];

long long res[N], ans;

void init(int N) {
    for (int i = 2; i &lt;= N; i++) {
        if (!flag[i]) {
            prime[++cnt] = i; res[i] = i; long long t = i;
            while (t &lt;= 10000000ll) res[t] = i, t *= i;
        }
        for (int j = 1; j &lt;= cnt &amp;&amp; 1ll * i * prime[j] &lt;= 1ll * N; j++) {
            flag[i * prime[j]] = 1; if (i % prime[j] == 0) break;
        }
    }
}

int main() {
    int l = read(), r = read();
    for (int i = l; i &lt;= r; i++) res[i] = 1;
    init(10000000);
    for (int i = l; i &lt;= r; i++) ans += res[i];
    printf("%lld", ans);
    return 0;
}
```</queue></algorithm></cstring></cmath></cstdio></iostream>
全部评论

相关推荐

哞客37422655...:兄弟别慌!💪 民办本找实习确实难点,但不是没机会。100+简历才2个面试,可能简历需要优化下: 项目经历写具体点,突出测试用例、bug数量等 技能栏把测试工具/方法论写清楚 可以考虑降低预期,先进小厂积累经验 测试岗相对好进,坚持投!现在才半个月,有人投3个月才上岸的😭 加油,offer在路上了🚀
点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务