题意  假设一个正整数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. JavaEE Tutorials (5) - 运行企业bean示例

    5.1cart示例56 5.1.1业务接口57 5.1.2会话bean类57 5.1.3@Remove方法61 5.1.4辅助类61 5.1.5运行cart示例615.2一个单例会话bean示例:co ...

  2. css3属性——border-radius用法

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <style> ...

  3. ubuntu中在线升级python

    sudo add-apt-repository ppa:fkrull/deadsnakes-python2.7 sudo apt-get update sudo apt-get upgrade 笔记

  4. DTM initialization: failure during startup recovery, retry failed, check segment status (cdbtm.c:1603)

    安装greenplum集群出现以下错误: 20160315:13:49:16:025696 gpinitsystem:h95:jason-[INFO]:-Checking configuration ...

  5. BZOJ 1797: [Ahoi2009]Mincut 最小割( 网络流 )

    先跑网络流, 然后在残余网络tarjan缩点. 考虑一条边(u,v): 当且仅当scc[u] != scc[v], (u,v)可能出现在最小割中...然而我并不会证明 当且仅当scc[u] = scc ...

  6. js window.onload事件

    1.最简单的调用方式 直接写到html的body标签里面,如: ? 1 2 3 4     <html>       <body onload="func()"& ...

  7. USACO Ski Course Design 暴力

    从Min到Max范围内暴力一下即可. /* ID: wushuai2 PROG: skidesign LANG: C++ */ //#pragma comment(linker, "/STA ...

  8. ZOJ2849 优先队列BFS

    Attack of Panda Virus Time Limit: 3 Seconds      Memory Limit: 32768 KB In recent months, a computer ...

  9. IE6多出一只猪的经典bug

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 基于visual Studio2013解决算法导论之027hash表

     题目 hash表,用链表来解决冲突问题 解决代码及点评 /* 哈希表 链接法解决冲突问题 */ #include <iostream> using namespace std; s ...