ZOJ 3622 Magic Number 打表找规律
2015-03-05 20:59
288 查看
A - Magic Number
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice ZOJ 3622
Appoint description:
Description
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
Sample Output
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice ZOJ 3622
Appoint description:
Description
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 思路:首先我们得用数学方法推出 只要满足10^ans%a==0,就是magic数,ans指的是a这个数的位数 题解:找规律,然后人工打表……
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int a1[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; int a2[10] = {2,20,200,2000,20000,200000,2000000,20000000,200000000,2000000000}; int a3[10] = {5,50,500,5000,50000,500000,5000000,50000000,500000000}; int a4[10] = {25,250,2500,25000,250000,2500000,25000000,250000000}; int a5[10] = {125,1250,12500,125000,1250000,12500000,125000000,1250000000}; int main() { int ans,n,m,i; while(~scanf("%d%d",&n,&m)) { ans = 0; if(n>m) swap(n,m); for(i = 0;i<10;i++) if(n<=a1[i] && a1[i]<=m) ans++; for(i = 0;i<10;i++) if(n<=a2[i] && a2[i]<=m) ans++; for(i = 0;i<9;i++) if(n<=a3[i] && a3[i]<=m) ans++; for(i = 0;i<8;i++) if(n<=a4[i] && a4[i]<=m) ans++; for(i = 0;i<8;i++) if(n<=a5[i] && a5[i]<=m) ans++; printf("%d\n",ans); } return 0; }
相关文章推荐
- 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 3785-What day is that day?-数论(费马小定理) / 打表找规律
- zoj 3622 Magic Number
- zoj 3785 打表找规律
- ZOJ 3876 May Day Holiday(找规律||打表-基姆拉尔森计算公式(求某年某月某日星期几))
- zoj 3622 Magic Number (构造?)
- ZOJ 3622 —— Magic Number(水题)
- ZOJ 3939 The Lucky Week 找规律打表
- Magic Number - ZOJ 3622 水题
- ZOJ-3768:Continuous Login(打表找规律+暴力)
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
- ZOJ 3622 Magic Number(数)
- ZOJ 3785 11th省赛 J What day is that day?【打表找规律】
- ZOJ-3785-What day is that day?【11th浙江省赛】【打表找规律】【快速幂】
- zoj 3629 Treasure Hunt IV 打表找规律