zoukankan      html  css  js  c++  java
  • codeforces 546D Soldier and Number Game

    题目链接

    这个题, 告诉你a, b的值, 那么只需要求出b到a之间的数, 每个数有多少个因子就可以。

    具体看代码, 代码里面有解释

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define pb(x) push_back(x)
     4 const int maxn = 5000005;
     5 int p[maxn], c[maxn];
     6 int main()
     7 {
     8     memset(p, 0, sizeof(p));
     9     memset(c, 0, sizeof(c));
    10     for(int i = 2; i<=maxn; i++) {
    11         if(!p[i]) {
    12             p[i] = i;
    13             for(int j = i+i; j<=maxn; j+=i) {
    14                 p[j] = i;                //求出一个数的最大素因子
    15             }
    16         }
    17     }
    18     for(int i = 2; i<=maxn; i++) {
    19         p[i] = p[i/p[i]]+1;             //这里, p[4]就等于p[2]+1, p[8] = p[8/2]+1 = p[4]+1这样类推就可以求出答案 
    20         c[i] = c[i-1]+p[i];
    21     }
    22     int t, a, b;
    23     cin>>t;
    24     while(t--) {
    25         scanf("%d%d", &a, &b);
    26         printf("%d
    ", c[a]-c[b]);
    27     }
    28 }    
  • 相关阅读:
    每日日报2021.2.5
    每日日报2021.2.4
    每日日报2021 3/8
    每日日报2021 3/7
    每日日报2021 3/6
    每日日报2021 3/5
    每日日报 2021 3.4
    每日日报2021 3/3
    开课博客
    217. Contains Duplicate
  • 原文地址:https://www.cnblogs.com/yohaha/p/5023306.html
Copyright © 2011-2022 走看看