昨天的CF div2 D:D
昨天打表发现这个规律了,但是就是写不出来,知道是这个问题,还是我的代码量太少了
题目大意:
给两个数 n,m,问你在x<=m的所有数里面,有x*n的后缀零最多的x*n的值是多少。
思路分析:
要想让末尾出现 0 ,最简单的想法就是乘以10,但是折磨做复杂度太高了,但是我们发现2*5=10,所以只要确定n 里面有几个2,和5,就可以确定最多可以出现几个10
AC代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;
ll n,m;
void IOS(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
}
void solve(){
cin>>n>>m;
ll t=n,c1=0,c2=0;
while(n%(ll)2==0){
n/=(ll)2;
c1++;// 2 的个数
}
while(n%(ll)5==0){
n/=(ll)5;
c2++;// 5的个数
}
ll d=1;
while(c1<c2&&d*2<=m)d*=(ll)2,c1++;
while(c2<c1&&d*5<=m)d*=(ll)5,c2++;
while(d*(ll)10<=m)d*=(ll)10;
ll h=m/d;
d *= h;
cout<<d*t<<endl;
}
int main(){
IOS();
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}