zoukankan      html  css  js  c++  java
  • zzuli 1902: 985的因子对难题

    ***这道题明显是在卡时间,类比快速打素数表的算法,***

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<cctype>
    #include<queue>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    typedef long long LL;
    #define N 100100
    #define INF 0x3f3f3f3f
    
    int num[N], fac[N];
    
    int main()
    {
        int T, n, a, Max;
        scanf("%d", &T);
    
        while(T--)
        {
            scanf("%d", &n);
            memset(num, 0, sizeof(num));
            memset(fac, 0, sizeof(fac));
            Max=-1;
            for(int i=0; i<n; i++)
            {
                scanf("%d", &a);
                num[a]++;
                if(Max<a)
                    Max=a;
            }
            for(int i=1; i<=Max; i++)
            {
                if(num[i])
                {
                    for(int j=2*i; j<=Max; j+=i)
                    {
                        fac[i]+=num[j];
                    }
                }
            }
    
            LL ans=0;
            for(int i=1; i<=Max; i++)
            {
                if(num[i]>1) ans+=num[i]*(num[i]-1)/2;
                ans+=num[i]*fac[i];
            }
            printf("%lld
    ", ans);
        }
        return 0 ;
    }
  • 相关阅读:
    C/C++内存对齐
    Fibonacci
    Count 1 in Binary
    Hash Function
    Fast Power
    Update Bits
    Unique Binary Search Trees
    Java知识体系(持续更新)
    如何发现牛股
    OpenResty究竟解决了什么痛点
  • 原文地址:https://www.cnblogs.com/9968jie/p/5775310.html
Copyright © 2011-2022 走看看