题意  假设一个正整数y满足  将随意正整数x放到y的左边得到的数z满足 z%y==0  那么这个数就是个Magic Number   给你一个范围  求这个范围内Magic Number的个数

令 l表示y的位数  ly=10^l  那么z=x*ly + y  要z%y==0   easy看出  仅仅需 x*ly%y==0

又由于x是随意的  所以一个Magic Number必须满足 ly%y==0

y<2^31  所以l最大为10 直接枚举l  找到全部符合的y即可了

当 ly%y==0
 时  y>=ly/10&&y<ly  即ly是比y多一位数的 令t=ly/y
 那么肯定有 1<t<=10  对于每一个ly  我们就仅仅用枚举t了

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 50;
typedef long long ll;
ll p[N], n, m; int main()
{
int cnt = 0, ans; //ly为10^l
for(ll ly = 10; ly < 1e11; ly *= 10)
{
for(ll t = 10; t > 1; --t) //若(ly/y==t) 必有1<t<=10
if(ly % t == 0) p[cnt++] = ly / t;
} while(~scanf("%lld%lld", &n, &m))
{
ans = upper_bound(p, p + cnt, m) - lower_bound(p, p + cnt, n);
printf("%d\n", ans);
}
return 0;
}

Magic Number


Time Limit: 2 Seconds      Memory Limit: 32768 KB


A positive number y is called magic number if for every positive integer x it satisfies that put y to the right of x, which will form a new integer zz mod y =
0.

Input

The input has multiple cases, each case contains two positve integers mn(1 <= m <= n <= 2^31-1), proceed to the end of file.

Output

For each case, output the total number of magic numbers between m and n(mn inclusively).

Sample Input

1 1
1 10

Sample Output

1
4

ZOJ 3622 Magic Number(数)的更多相关文章

  1. ZOJ 3622 Magic Number 打表找规律

    A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  2. [ZOJ 3622] Magic Number

    Magic Number Time Limit: 2 Seconds      Memory Limit: 32768 KB A positive number y is called magic n ...

  3. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  4. 一个快速double转int的方法(利用magic number)

    代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...

  5. poj magic number

    Problem H Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  6. 幻数浅析(Magic Number)

    在源代码编写中,有这么一种情况:编码者在写源代码的时候,使用了一个数字,比如0x2123,0.021f等,他当时是明白这个数字的意思的,但是别的程序员看他的代码,可能很难理解,甚至,过了一段时间,代码 ...

  7. Magic Number(Levenshtein distance算法)

    Magic Number Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  8. LVM XFS增加硬盘分区容量(resize2fs: Bad magic number in super-block while)

    LVM XFS增加硬盘分区容量(resize2fs: Bad magic number -- :: 分类: Linux LVM XFS增加硬盘分区容量(resize2fs: Bad magic num ...

  9. iOS Exception Code 之 Magic Number

    https://en.wikipedia.org/wiki/Hexspeak  iOS Exception Code 之 Magic Number 备忘.

随机推荐

  1. imagemagick /tmp/magick-xxxxxxxx

    问题 imagemagick在某种场景下会狂写/tmp目录,文件名形如magick-xxxxxxxx, ls -lh查看这些文件达到几百G, du -sh查看则只有几十M 被这个问题折磨了许久,大晚上 ...

  2. vs提示“当前不会命中断点,源代码与原始版本不同”的一种解决办法

    将出问题的cpp文件用notepad打开,另存为‘unicode’类型,覆盖源文件即可

  3. 2014 北京邀请赛ABDHJ题解

    A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...

  4. String详解说明

    大家平时都string都不是很在意,但是每当面试碰到String的时候在“==”和equals之间就乱了,下面我来说一说String,也许不够全面,请大家多多指教,希望会帮到处于蒙圈状态的人们. 一. ...

  5. Talented Chef(简单题,被我想的太复杂了,用复杂的方法当然会超时咯,由此可见,并非所有题都是想的越多越好)

    Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...

  6. CUDA纹理绑定

    纹理绑定的一般步骤: size_t fea_pitch; texture<unsigned char, 2> features2D; cudaMallocPitch((void**)(&a ...

  7. c# 数据库编程(利用DataSet 和 DataAdaper对象操作数据库--单表操作)

    一.概述 前面2篇文章,介绍了使用SqlCommand对象利用sql命令来操作数据库. 这篇文章我们来介绍使用c#的DataSet 和 DataAdaper对象操作操作数据库. 先来介绍下这两个对象是 ...

  8. vnc server配置、启动、重启与连接,图形管理linux系统

    环境:RedHat Linux 5企业版.Xwindows:gnome (红帽默认安装的图形界面) 尽管我们可以使用SSH连接远程通过字符界面来操作Linux,但是对于更多熟悉图形人来说是很不方便的, ...

  9. 第一次PS练习

    嘿嘿,自己第一次的PS,虽然把在大神眼里是小KS,但是了,对我来说值得劲纪念.加油,我会努力的.

  10. inheritAll 及 ant antfile案例分析

    <?xml version="1.0"?> <project name="a" default="targeta"> ...