zoukankan      html  css  js  c++  java
  • P2429 制杖题

    P2429 制杖题
    这个题用线性筛会WA一个点,因为这个题是给定的质数集,最大的质数会比当前的倍数大,就会出现上面的情况。
    怎办?
    判重用set啊!
    set+线性筛就过掉了。16ms

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<set>
     7 #include<ctime>
     8 #include<cstring>
     9 #define mod 376544743
    10 #define inf 2147483647
    11 #define For(i,a,b) for(register long long i=a;i<=b;i++)
    12 #define p(a) putchar(a)
    13 #define g() getchar()
    14 //by war
    15 //2017.10.19
    16 using namespace std;
    17 long long n,m;
    18 long long prime[100];
    19 long long tot;
    20 set<long long>s;
    21 void in(long long &x)
    22 {
    23     long long y=1;
    24     char c=g();x=0;
    25     while(c<'0'||c>'9')
    26     {
    27     if(c=='-')
    28     y=-1;
    29     c=g();
    30     }
    31     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
    32     x*=y;
    33 }
    34 void o(long long x)
    35 {
    36     if(x<0)
    37     {
    38         p('-');
    39         x=-x;
    40     }
    41     if(x>9)o(x/10);
    42     p(x%10+'0');
    43 }
    44 
    45 void Euler()
    46 {
    47     For(i,1,m/prime[1])
    48     {
    49         for(int j=1;j<=n&&prime[j]*i<=m;j++)
    50         {
    51             if(!s.count(prime[j]*i))
    52             {
    53             tot=(tot+prime[j]*i)%mod;
    54             s.insert(prime[j]*i);    
    55             }
    56             if(i%prime[j]==0)
    57             break;
    58         }
    59     }
    60 }
    61 
    62 int main()
    63 {
    64     
    65     in(n),in(m);
    66     For(i,1,n)
    67     in(prime[i]);
    68     sort(prime+1,prime+n+1);
    69     Euler();
    70     o(tot%mod);
    71      return 0;
    72 }
  • 相关阅读:
    k8s资源需求和限制, 以及pod驱逐策略
    python转义引起的错误
    nginx location 匹配目录
    kubelet 证书自动续期
    docker常见退出码
    (转)firefox火狐浏览器语言设置
    去掉表的identity属性
    SQL Server内存方面知识收集
    SQL Server 中not in和not exists
    Data Compression(1)
  • 原文地址:https://www.cnblogs.com/war1111/p/7698718.html
Copyright © 2011-2022 走看看