Magic Number (zoj3622)
2013-11-19 20:11
148 查看
Magic Number (zoj3622)
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 21 Accepted Submission(s) : 7
[align=left]Problem Description[/align]
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 [b]开始不理解题意,后来同学给我讲了之后才理解 [/b]
[b]题意;得 xy mod y = 0 ,变形即得 (x*10^(y的位数)+y)mod y = 0, 化简得 x*10^(y的位数) mod y = 0 ,题目说对于任意的 x,y都得成立, 所以只要 y 是 10^(y的位数) 的因子即可。但是这道题卡时,做的时候老超时, 到最后不得不把数据范围内的所有数都打出来,没办法,,,我只能说我能力不够啊,,,还是太水了,,, 附代码:[/b]
/* #include<stdio.h> #include<math.h> int main() { __int64 x,y,t=0,m,k; while(scanf("%I64d%I64d",&x,&y)!=EOF) { int i,j; k=0; for(i=1;i<pow(2,31);i++) { t=0; m=i; while(m) {t++;m/=10;} int p=1; for(j=1;j<=i;j++) { if((j*(__int64)pow(10,t))%i) {p=0;break;} } if(p) {printf("%I64d ",i);} } printf("\n"); } return 0; } //我表示时间很漫长,但是你会找到规律的,所以之后的自己写好了,哈哈 */ /* #include<stdio.h> #include<math.h> int main() { __int64 x,y,t=0,m,k; while(scanf("%I64d%I64d",&x,&y)!=EOF) { int i,j; k=0; for(i=1;i<100;i++) { t=0; m=i; while(m) {t++;m/=10;} int p=1; for(j=1;j<=i;j++) { if((j*(__int64)pow(10,t))%i) {p=0;break;} } if(p) {printf("%I64d ",i);} } __int64 a=100,b=125,c=200,d=250,e=500; for(;a<pow(2,31);)//有了上面的规律,这样就可以全部输出来了。。。很快的,哈哈 { printf("%I64d %I64d %I64d %I64d %I64d ",a,b,c,d,e); a*=10; b*=10; c*=10; d*=10; e*=10; } printf("\n"); } return 0; } */ #include<stdio.h> long long int a[55]={1,2,5,10,20,25,50,100,125,200,250,500,1000,1250,2000,2500,5000,10000,12500,20000,25000,50000,100000,125000,200000,250000,500000,1000000,1250000,2000000,2500000,5000000,10000000,12500000,20000000, 25000000, 50000000,100000000 ,125000000, 200000000, 250000000, 500000000,1000000000 ,1250000000, 2000000000, 2500000000,5000000000,10000000000 ,12500000000, 20000000000}; int main()//我晕,__int64不然过,,,long long 就过了,错误是 Getting complication error information failed! 求解释! { long long int m,n; while(scanf("%lld%lld",&m,&n)!=EOF) { int i,count=0; for(i=0;i<55;i++) { if(m<=a[i]&&a[i]<=n) count++; if(a[i]>n) break; } printf("%lld\n",count); } return 0; }
这是第一个程序,,,寻找规律。
[b]然后第二个程序,就出来了。 太心酸了,用int64,PE了N次,改longlong,秒过,求大神解答。[/b]
相关文章推荐
- ZOJ3622:Magic Number
- [简单DP] HDOJ 4323 Magic Number
- zoj 3622 Magic Number
- ZOJ 3622 Magic Number 打表找规律
- Magic number
- magic number
- HDU 4323 Magic Number(DP)
- HDU - 4323 - Magic Number
- zoj 3622 Magic Number(找规律)
- iOS Exception Code 之 Magic Number
- Magic Number 在编程中的使用
- 计算机中的magic number
- 魔法数字(magic number)
- ZOJ 3622 Magic Number(打表)
- 什么是magic number
- hdu 4323 Magic Number
- 2014黑龙江省赛热身赛Magic number
- Magic Number(Levenshtein distance算法)
- 【HDU】5796 Magic Number【lca】