zoukankan      html  css  js  c++  java
  • bzoj1853 [Scoi2010]幸运数字

    题目链接

    容斥原理

    虽然只含6、8的数有很多

    但是题解告诉我真正互质的只有10+个woc

    然后容斥原理,注意爆long long ,用double 近似比较

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<string>
     7 #include<cmath>
     8 #include<ctime>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<set>
    13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
    15 #define Clear(a,b) memset(a,b,sizeof(a))
    16 #define inout(x) printf("%d",(x))
    17 #define douin(x) scanf("%lf",&x)
    18 #define strin(x) scanf("%s",(x))
    19 #define LLin(x) scanf("%lld",&x)
    20 #define op operator
    21 #define CSC main
    22 typedef unsigned long long ULL;
    23 typedef const int cint;
    24 typedef long long LL;
    25 using namespace std;
    26 void inin(int &ret)
    27 {
    28     ret=0;int f=0;char ch=getchar();
    29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
    30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
    31     ret=f?-ret:ret;
    32 }
    33 LL l,r,a[10010],b[10010],top,n,ans;
    34 bool bo[10010];
    35 LL gcd(LL a,LL b)
    36 {
    37     LL c;
    38     while(a%b)c=a%b,a=b,b=c;
    39     return b;
    40 }
    41 void hh(int aa,LL bb)
    42 {
    43     if(bb>r)return ;
    44     if(aa>0)a[++top]=bb;
    45     hh(aa+1,bb*10+6);
    46     hh(aa+1,bb*10+8);
    47 }
    48 void dfs(int aa,int bb,LL cc)
    49 {
    50     if(aa>n)
    51     {
    52         if(bb&1)ans+=r/cc-l/cc;
    53         else if(bb)ans-=r/cc-l/cc;
    54         return;
    55     }
    56     dfs(aa+1,bb,cc);
    57     LL temp=cc/gcd(a[aa],cc);
    58     if(((long double)a[aa]*temp)<=r)
    59        dfs(aa+1,bb+1,a[aa]*temp);
    60 }
    61 int CSC()
    62 {
    63     LLin(l),LLin(r);
    64     hh(0,0);
    65     sort(a+1,a+top+1);
    66     re(i,1,top)if(!bo[i])
    67     {
    68         b[++n]=a[i];
    69         re(j,i+1,top)if(!(a[j]%a[i]))bo[j]=1;
    70     }
    71     re(i,1,n)a[n-i+1]=b[i];l--;
    72     dfs(1,0,1);
    73     printf("%lld",ans);
    74     return 0;
    75 }
  • 相关阅读:
    Git 的版本库创建和修改
    appnium框架以及源码研究
    根据图片的URL生成PDF保存到本地(前台js)
    根据图片的URL生成PDF保存到服务器上(后台C#实现)
    麻烦的控件只读
    利用Javascript生成txt文本文件
    KendoUI AngularJS Bootstrap
    给Grid动态添加列和添加样式
    linq 分组求和的一般方法
    KendoUi学习之旅 Combobox的使用
  • 原文地址:https://www.cnblogs.com/HugeGun/p/5197163.html
Copyright © 2011-2022 走看看