幸运数字(number)
幸运数字(number)
Time Limit:1000ms Memory Limit:64MB
【题目描述】
LYK最近运气很差,例如在NOIP初赛中仅仅考了90分,刚刚卡进复赛,于是它决定使用一些方法来增加自己的运气值。它觉得,通过收集幸运数字可以快速的增加它的RP值。它给幸运数字下了一个定义:如果一个数x能被3整除或被5整除或被7整除,则这个数为幸运数字。于是它想让你帮帮它在L~R中存在多少幸运数字。
【输入格式】(number.in)
第一行两个数L,R。
【输出格式】(number.out)
一个数表示答案。
【输入样例】
10 15
【输出样例】
4
【数据范围】
对于50%的数据1<=L<=R<=10^5。
对于60%的数据1<=L<=R<=10^9。
对于80%的数据1<=L<=R<=10^18。
对于90%的数据1<=L<=R<=10^100。
对于另外10%的数据L=1,1<=R<=10^100。
对于100%的数据L,R没有前导0。
【题目分析】
从L到R中能被3 5 7整除的数字,那就算一下这个区间:3的倍数+5的倍数+7的倍数-15的倍数-35的倍数-21的倍数+105的倍数(容斥原理),要注意计算L之内的数的个数时,L不能算在内(跟 前缀和是同样的原理)
我们会发现后面还有两组数据的R<=10^100T_T ,高精,弃了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long l,r;
int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
scanf("%I64d%I64d",&l,&r);
l--;
long long ans1=l/+l/+l/-l/-l/-l/+l/;
long long ans2=r/+r/+r/-r/-r/-r/+r/;
cout << ans2-ans1;
fclose(stdin);fclose(stdout);
return ;
}
蒟蒻80
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
char s1[],s2[];
int S1[],S2[],len1,len2,s[],S[],i;
void pl(int *a,int *b)
{
for (int i=a[]+; i<=b[]; i++) a[i]=;
for (int i=; i<=b[]; i++) a[i]+=b[i];
a[]=max(a[],b[]);
for (int i=; i<a[]; i++) if (a[i]>=) {a[i+]++; a[i]-=;}
if (a[a[]]>=) {a[a[]+]=; a[a[]]-=; a[]++;}
}
void mn(int *a,int *b)
{
for (int i=a[]+; i<=b[]; i++) a[i]=;
for (int i=; i<=b[]; i++) a[i]-=b[i];
for (int i=; i<a[]; i++)
if (a[i]<) {a[i]+=; a[i+]--;}
while (a[]> && a[a[]]==) a[]--;
}
void work(int *a,int b,int *c)
{
for (int i=; i<=a[]; i++) c[i]=a[i];
for (int i=a[]; i>=; i--)
{
c[i-]+=c[i]%b*;
c[i]/=b;
}
c[]=a[];
while (c[]> && c[c[]]==) c[]--;
}
int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
scanf("%s",s1);
scanf("%s",s2);
len1=strlen(s1);
len2=strlen(s2);
for (i=; i<=len1; i++) S1[len1-i+]=s1[i-]-'';
S1[]=len1;
for (i=; i<=len2; i++) S2[len2-i+]=s2[i-]-'';
S2[]=len2;
work(S2,,s);
work(S2,,S);
pl(s,S);
work(S2,,S);
pl(s,S);
work(S2,,S);
mn(s,S);
work(S2,,S);
mn(s,S);
work(S2,,S);
mn(s,S);
work(S2,,S);
pl(s,S);
S[]=; S[]=;
mn(S1,S);
work(S1,,S);
pl(s,S);
work(S1,,S);
pl(s,S);
work(S1,,S);
pl(s,S);
work(S1,,S);
mn(s,S);
work(S1,,S);
mn(s,S);
work(S1,,S);
mn(s,S);
work(S1,,S);
mn(s,S);
for (i=s[]; i>=; i--) cout<<s[i];
return ;
}
std的话是长这个样子的
幸运数字(number)的更多相关文章
- 2014.11.12模拟赛【美妙的数字】| vijos1904学姐的幸运数字
美妙的数字(number.c/.cpp/.pas) 题目描述 黄巨大认为非负整数是美妙的,并且它的数值越小就越美妙.当然0是最美妙的啦. 现在他得到一串非负整数,对于每个数都可以选择先对它做二进制非运 ...
- 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2472 Solved: 911 Description 在中国 ...
- BZOJ1853 Scoi2010 幸运数字 【枚举+容斥】
BZOJ1853 Scoi2010 幸运数字 Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号 ...
- BZOJ 1853 【Scoi2010】 幸运数字
Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认 为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,8 ...
- BZOJ 4568 幸运数字
题目传送门 4568: [Scoi2016]幸运数字 Time Limit: 60 Sec Memory Limit: 256 MB Description A 国共有 n 座城市,这些城市由 n-1 ...
- BZOJ 1853: [Scoi2010]幸运数字
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2117 Solved: 779[Submit][Status] ...
- 【BZOJ-4568】幸运数字 树链剖分 + 线性基合并
4568: [Scoi2016]幸运数字 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 238 Solved: 113[Submit][Status ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- BZOJ1853 [Scoi2010]幸运数字
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
随机推荐
- poj: 2255
跟LEETCODE的preorder,inorder转postorder题很像 #include <iostream> #include <stdio.h> #include ...
- C++之路进阶——bzoj1030(文本生成器)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...
- URAL 1139 City Blocks(数论)
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...
- bzoj4238 电压
首先先直接对图进行二染色,dfs染完色后,有的边为搜索树边,有的为非树边,当非树边连接的两头的点为异色的时候,那么很明显这条非树边和树边构成的环上的边必然不可能成为答案:如果非树边的两端的点同色,那么 ...
- Android 封装Dialog
package com.example.myandroid01; import android.support.v7.app.ActionBarActivity; import android.os. ...
- oracle 分区表的维护
1:添加分区: ALTER TABLE SALES ADD PARTITION P3 VALUES LESS THAN(TO_DATE('2003-06-01','YYYY-MM-DD')); SAL ...
- 某个系统配置文件 用户层的SQL
SELECT fpo.user_profile_option_name, fpv.level_id, fpv.level_value, fpv.profile_option_value, fu.use ...
- 关于UIView(转)
曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...
- xx
[git]merge和rebase的区别 - 削微寒 - 博客园 http://www.cnblogs.com/vamei/p/3480994.html 协议森林16 小美的桌号(DHCP协议) - ...
- 【python cookbook】【字符串与文本】7.定义实现最短匹配的正则表达式
问题:使用正则表达式对文本模式匹配,将识别出来的最长的可能匹配修改为找出最短的可能匹配 解决方法:在匹配模式中的*操作符后加上?修饰符 import re # Sample text text = ' ...