zoj Majic Number(3622)
来源:互联网 发布:淘宝人气女装店铺 编辑:程序博客网 时间:2024/05/22 13:23
A positive number y is called magic number if for every positive integerx it satisfies that put y to the right of x, which will form a new integerz, 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 andn(m, n inclusively).
Sample Input
1 11 10
Sample Output
14
首先:我们写个程序写下前一10000 里面有哪些数。
#include <cstdio>#include <cstring>#include <cmath>int main(){int i,j;int temp;bool flag;int cnt = 0;for(i = 1;i<10000;i++){flag = true;for(j = 1;j<=9;j++){if(i<10) temp=j*10+i;else if(i<100) temp = j*100+i;else if(i<1000) temp = j*1000+i;else if(i<10000) temp = j*10000+i;if(temp%i!=0) {flag = false;break;}}if(flag) {printf("%d\n",i);cnt++;}}printf("%d\n",cnt);return 0;}1
2
5
10
20
25
50
100
125
200
250
500
1000
1250
2000
2500
5000
17
我们发现这些数都只会是 1,2,5,25,125 的倍数。
于是:
#include <cstdio>#define maxn 10000long long a[] = {1,2,5,25,125};int main(){int n,m;while(scanf("%d%d",&n,&m)!=EOF){int ans = 0;for(int i = 0;i<5;i++){long long x = a[i];while(x<=m){if(x>=n) ans++;x*=10;}}printf("%d\n",ans);}return 0;}
伟大的梦想成就伟大的人,从细节做好,从点点滴滴做好,从认真做好。
0 0
- zoj Majic Number(3622)
- zoj 3622 Magic Number
- zoj 3622 Magic Number
- ZOJ 3622 Magic Number 月赛水题
- Magic Number - ZOJ 3622 水题
- zoj 3622 Magic Number 【规律】
- ZOJ 3622 Magic Number(数)
- 【数学规律】-ZOJ-3622-Magic Number
- ZOJ-#3622 Magic Number(找规律)
- ZOJ——3622 Magic Number
- zoj 3622 Magic Number(找规律)
- ZOJ 3622 Magic Number(打表)
- ZOJ 1039 Number Game
- zoj 1526 Big Number
- ZOJ 2829 Beautiful Number
- zoj 2105 Number Sequence
- zoj 1526 Big Number
- zoj 3327 Friend Number
- 文件系统相关
- SQL高级(1)
- Android Context应用上下文详解
- poj2488A Knight's Journey
- pctfree和pctused
- zoj Majic Number(3622)
- MySql学习笔记3:where语句
- O(n)算法得到数组中任意第k大的数字
- Struts2上传文件报错Unable to parse request org.apache.commons.fileupload.FileUploadBase$IOFileUploadExcept
- mailfeet and webfeet
- Delphi中给Windows服务程序添加描述信息
- 通信算法之四:九种调试方式理论误码率与实际误码率
- 手工安装配置Cloudera组件-Impala
- POJ 1006 孙子定理