• zoj 2095 Divisor Summation


    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1095

    题目大意:求正整数 n 的真因子之和

    解题思路:类似素数筛法

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: zoj 2095
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 typedef long long LL;
    26 const double PI=acos(-1.0);
    27 
    28 const int x4[]={-1,0,1,0};
    29 const int y4[]={0,1,0,-1};
    30 const int x8[]={-1,-1,0,1,1,1,0,-1};
    31 const int y8[]={0,1,1,1,0,-1,-1,-1};
    32 
    33 typedef int T;
    34 T max(T a,T b){ return a>b? a:b; }
    35 T min(T a,T b){ return a<b? a:b; }
    36 ///////////////////////////////////////////////////////////////////////////
    37 
    38 ///////////////////////////////////////////////////////////////////////////
    39 //Add Code:
    40 int ans[500005];
    41 ///////////////////////////////////////////////////////////////////////////
    42 
    43 int main(){
    44     ///////////////////////////////////////////////////////////////////////
    45     //Add code:
    46     int Case,n,i,j;
    47     ans[1]=0;
    48     for(i=1;i<=250000;i++){
    49         for(j=i+i;j<=500000;j+=i) ans[j]+=i;
    50     }
    51     scanf("%d",&Case);
    52     while(Case--){
    53         scanf("%d",&n);
    54         printf("%d
    ",ans[n]);
    55     }
    56     ///////////////////////////////////////////////////////////////////////
    57     return 0;
    58 }
    59 
    60 ///////////////////////////////////////////////////////////////////////////
    61 /*
    62 Testcase:
    63 Input:
    64 3
    65 2
    66 10
    67 20
    68 Output:
    69 1
    70 8
    71 22
    72 */
    73 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    ajax异步更新的理解
    Java 中的匿名内部类
    Java 中的方法内部类
    Java 中的静态内部类
    Java 中的成员内部类
    Java 中的 static 使用之静态方法(转)
    构造方法
    成员变量与局部变量的区别
    script标签属性sync和defer
    jsonp原理
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3281520.html
Copyright © 2020-2023  润新知