您的位置:首页 > 其它

【数学规律】-ZOJ-3622-Magic Number

2014-06-30 08:41 197 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3622

题目描述:找这样的数 y 。把 y 放在任意一个自然数的右侧,构成的新数能被 y 整除。

解题思路:

想一下~

一位数: 1 ,2 ,5

两位数: 10, 20, 50, 25

三位数: 100, 200, 500, 250 ,125

四位数: 1000, 2000, 5000, 2500 ,1250

没错,就是这样,依次类推到九位数就够用了,手工写个表就过了。。差点就能抢到一血了,,唉

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int arr[45] = {
10,
1,
2,
5,
100,
20,
50,
25,
1000,
200,
500,
250,
125,
10000,
2000,
5000,
2500,
1250,
100000,
20000,
50000,
25000,
12500,
1000000,
200000,
500000,
250000,
125000,
10000000,
2000000,
5000000,
2500000,
1250000,
100000000,
20000000,
50000000,
25000000,
12500000,
1000000000,
200000000,
500000000,
250000000,
125000000,
2000000000,
1250000000
};

int main()
{
//freopen("input.txt","r",stdin);
int m,n,i;
while(cin>>m>>n)
{
int ans=0;
for(i=0;i<45;i++)
if(arr[i]>=m && arr[i]<=n) ans++;
cout<<ans<<endl;
}
return 0;
}

AC截图:





  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  入门基础 数学 zoj