zoukankan      html  css  js  c++  java
  • HNU 12876 Quite Good Numbers 完美数变形

    筛法是一种很快的方法,贴代码纪念一下。 做法很像筛法

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cmath>
     6 #include <algorithm>
     7 #include <string>
     8 #include <queue>
     9 #include <stack>
    10 #include <vector>
    11 #include <map>
    12 #include <set>
    13 #include <functional>
    14 #include <time.h>
    15 
    16 using namespace std;
    17 
    18 const int INF = 1<<30;
    19 const int MAXN = (int) 1e6+5;
    20 
    21 int a[MAXN];
    22 
    23 inline int myAbs(int x) {
    24     return x>0 ? x : -x;
    25 }
    26 
    27 int main() {
    28     #ifdef Phantom01
    29         freopen("HNU12876.in", "r", stdin);
    30     #endif //Phantom01
    31 
    32     memset(a, 0, sizeof(a));
    33     for (int i = 1; i < MAXN; i++)
    34         for (int j = i<<1; j < MAXN; j += i)
    35             a[j]+=i;
    36     for (int i = 1; i < MAXN; i++)
    37         a[i] = myAbs(a[i]-i);
    38 
    39     int l, r, k;
    40     int T = 1;
    41     while (scanf("%d%d%d", &l, &r, &k)!=EOF) {
    42         if (l==r&&r==k&&k==0) break;
    43         printf("Test %d: ", T++);
    44         int ans = 0;
    45         for (int i = l; i <= r; i++)
    46             if (a[i]<=k)
    47                 ans++;
    48         printf("%d
    ", ans);
    49     }
    50 
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    muduo库源码剖析(一) reactor模式
    POSIX 线程编程(二)线程建立与终止
    visual assist常用快捷键
    Linux下 静态链接库 和 动态链接库
    linux(Ubuntu)下mysql字符集完美解决
    共享内存解读
    hdu2829
    hdu3525
    2013ACM-ICPC亚洲区南京站现场赛G题
    poj1487
  • 原文地址:https://www.cnblogs.com/Phantom01/p/3902407.html
Copyright © 2011-2022 走看看