Question link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3622.
Question:
If a number x meets the following conditions:
If you add a number Y to the left of X, the Yx value is a multiple of X. For example, if 1 is satisfied, 2 is satisfied, and 5 is satisfied.
Then I first thought that the 10 times of 1 2 5 was 10 20 50,100 200 500 and many, and then I found a bug of 25. I found that there was a problem with the search rule.
It was found that 10 100 1000 10000 divided by 1 2 3 4 5 6 7 8 9,
If the remainder is 0, it indicates that the operator meets the conditions.
For example, if 10 is the divisor, 10 5 2 1
For example, if 100 is the divisor, 100 50 25 20 10 meets the conditions.
The rule is the same as above. You can find all matching items and search them again.
ll a[1000000];int main(){ ll i,j,n,m; ll cnt = 0; for(i=10;i<=100000000000LL;i*=10){ for(j=10;j>=1;j--){ if(!(i%j)){ if(i/j==a[cnt-1]) continue; a[cnt++] = i / j; //cout<<a[cnt-1]<<endl; } } } while(scanf("%lld%lld",&n,&m)!=EOF){ int sum = 0; for(i=0;i<cnt;i++){ if(a[i]>=n&&a[i]<=m) sum++; if(a[i]>m) break; } printf("%d\n",sum); } return 0;}
Zoj 3622 magic number [rule]