ZOJ 3622 Magic Number(打表)
2015-07-21 00:04
316 查看
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 z, z mod y =
0.
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 z, z mod y =
0.
Input
The input has multiple cases, each case contains two positve integers m, n(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(m, n inclusively).Sample Input
1 1 1 10
Sample Output
1 4 题意:有一类数,该数放在任何数的右面后形成的新数对原数取余为0。例如2,无论2放在什么数的右面,形成的数总是偶数,因此对2取余都为0.给出m和n求两者之间有多少个这样的数。题解:这些数必须是1,10,100,1000,10000.。。。的因子。直接 求出这些数的因子 再遍历即可。#include<cstring> #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<vector> #include<algorithm> #define ll long long using namespace std; vector<ll>vec; void init() { vec.push_back(1); ll fa=10; int k=2; while(k<=11) { ll x=fa; ll y=fa/10; vec.push_back(x); for(ll i=2; i*i<=x; i++) { if(x%i==0) { if(i>y)vec.push_back(i); ll j=x/i; if(j==i)continue; if(j>y)vec.push_back(j); } } fa*=10; k++; } } void debug() { sort(vec.begin(),vec.end()); for(int i=0; i<vec.size(); i++) { printf("%lld ",vec[i]); } cout<<endl; } int main() { //freopen("test.in","r",stdin); init(); //debug(); ll n,m; while(cin>>n>>m) { int ans=0; for(int i=0; i<vec.size(); i++) { if(vec[i]>=n&&vec[i]<=m)ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- java 处理XML(dom4j-1.6.1)
- OC学习-单例设计模式的理解、案例和简单总结
- 运行hbm2java工具和hbm2ddl工具
- C#6.0中10大新特性的应用和总结
- ASP.NET通过自定义函数实现对字符串的大小写切换功能
- 页面编码codepage=936和65001的区别
- 剖析Django中模版标签的解析与参数传递
- 详解Python的Django框架中inclusion_tag的使用
- 编写自定义的Django模板加载器的简单示例
- 举例讲解Django中数据模型访问外键值的方法
- Django的数据模型访问多对多键值的方法
- 通过数据库对Django进行删除字段和删除模型的操作
- 详解Python的Django框架中Manager方法的使用
- 在Django的模型中添加自定义方法的示例
- 在Django的模型中执行原始SQL查询的方法
- 在Python的Django框架中使用通用视图的方法
- Django框架中的对象列表视图使用示例
- 在Django的通用视图中处理Context的方法
- 在Python的Django框架中显示对象子集的方法
- 详解Django通用视图中的函数包装