ZOJ 3622 Magic Number
2012-07-29 21:28
309 查看
Magic NumberTime 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.
Author: QU, Zhe
Contest: ZOJ Monthly, July 2012
//下午月赛的第一题
//开始少了2个数,郁闷了
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <stack>
using namespace std;
int dp[100];
int nu;
void set()
{ dp[nu++]=1;
int r[5]={1,2,4,5,8};
int i,j;
for(i=10;i<=1000000000;i*=10)
{
for(j=0;j<5;j++)
if(i%r[j]==0)
dp[nu++]=i/r[j];
}
}
int main()
{
set();
int i,k;
sort(dp,dp+nu);
dp[nu++]=1250000000;
dp[nu++]=2000000000;
int n,m;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(k=i=0;i<nu;i++)
if(m<=dp[i]&&n>=dp[i])
k++;
printf("%d\n",k);
}
return 0;
}
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
Author: QU, Zhe
Contest: ZOJ Monthly, July 2012
//下午月赛的第一题
//开始少了2个数,郁闷了
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <stack>
using namespace std;
int dp[100];
int nu;
void set()
{ dp[nu++]=1;
int r[5]={1,2,4,5,8};
int i,j;
for(i=10;i<=1000000000;i*=10)
{
for(j=0;j<5;j++)
if(i%r[j]==0)
dp[nu++]=i/r[j];
}
}
int main()
{
set();
int i,k;
sort(dp,dp+nu);
dp[nu++]=1250000000;
dp[nu++]=2000000000;
int n,m;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(k=i=0;i<nu;i++)
if(m<=dp[i]&&n>=dp[i])
k++;
printf("%d\n",k);
}
return 0;
}
相关文章推荐
- 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 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 3622 Magic Number(数)
- zoj 3622
- zoj 3622
- zoj Majic Number(3622)