bzoj 2393(容斥原理)
来源:互联网 发布:github客户端 for mac 编辑:程序博客网 时间:2024/05/04 15:36
2393: Cirno的完美算数教室
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 394 Solved: 231
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
58
解题思路:先可以枚举出baka数,然后再删掉两两可以整除的。
然后在dfs,加点剪枝,就是当lcm>r时直接退出。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long l,r,len,cnt,ans;
long long q[2000],g[2000];
bool b[2000];
inline long long read()
{
char y; long long x=0,f=1; y=getchar();
while (y<'0' || y>'9') {if (y=='-') f=-1; y=getchar();}
while (y>='0' && y<='9') {x=x*10+int(y)-48; y=getchar();}
return x*f;
}
long long gcd(long long a,long long b)
{
if (b==0) return a;
else return gcd(b,a%b);
}
void dfs(long long sum)
{
if (sum>r) return;
if (sum!=0)++len,q[len]=sum;
dfs(sum*10+2);
dfs(sum*10+9);
}
void work(long long sum,int ge,int now)
{
if (sum>r) return;
if (now==cnt+1)
{
if (sum!=1) {if (ge%2==1)ans+=r/sum-(l-1)/sum;else ans-=r/sum-(l-1)/sum;}
return;
}
long long ogg=gcd(sum,g[now]);
work(sum*g[now]/ogg,ge+1,now+1);
work(sum,ge,now+1);
}
int main()
{
l=read(); r=read();
dfs(0);
memset(b,true,sizeof(b));
for (int i=1;i<=len;++i)
for (int j=1;j<=len;++j)
if (i!=j && q[i]%q[j]==0) b[i]=false;
for (int i=1;i<=len;++i)
if (b[i])
{
++cnt; g[cnt]=q[i];
}
ans=0;
work(1,0,1);
printf("%lld",ans);
}
- bzoj 2393(容斥原理)
- BZOJ 2393 容斥原理
- bzoj 2393 & bzoj 1853 容斥原理
- 【bzoj】2190 - 仪仗队(容斥原理)
- bzoj 3622 容斥原理
- BZOJ 2005 容斥原理
- BZOJ 2045 容斥原理
- bzoj 1853 容斥原理
- BZOJ 2393: Cirno的完美算数教室 容斥原理
- BZOJ 1042(简单DP+容斥原理)
- bzoj 1853: [Scoi2010]幸运数字(容斥原理)
- bzoj 1042: [HAOI2008]硬币购物(容斥原理)
- 【bzoj 1853】 [Scoi2010] 幸运数字(容斥原理)
- 【bzoj 1042】 [HAOI2008] 硬币购物(dp+容斥原理)
- bzoj 3198: [Sdoi2013]spring (hash+容斥原理)
- bzoj 4710: [Jsoi2011]分特产 (容斥原理+DP)
- bzoj 2839: 集合计数 (容斥原理)
- bzoj 2986: Non-Squarefree Numbers (容斥原理)
- 51nod 1298 圆与三角形(计算几何)
- 微信消息模板的配置
- JAVA 学习模块七: 二维数组
- Java中被搁置的“goto”保留字
- C枚举类型的使用方法
- bzoj 2393(容斥原理)
- CDH5.X完全卸载步骤
- RimWorld模组教程之地板
- 64 位编译环境搭建
- 【IT】中国码农生存现状调查
- NodeList对象
- [编程题] LeetCode上的Dynamic Programming(动态规划)类型的题目
- 结构体大小的判断
- FRmebuffer workflow