G - Make It Round CodeForces - 1759D

给定一个商品的价格,再给一个价格提高到的倍数,求使得商品扩大到多少倍时使得商品价格最后的0最多,如果有多个价格0一样多,输出最大的那一个。如果不可能得到一个后缀0多的价格,输出扩大系数最多时的价格(n*m)。

/*思路:先找出n中未成对的2或5,由m来补,再从m中找剩下的10(如果有的话),然后看看能是整0的几倍*/
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
string s;
#define maxn 03f3f3f3f
#define int long long
void solve()
{
    int n,m;
    vector<int>v;
    cin >> n>>m;
    int ans = 0;
    int mm = 0;
    int cnt2=0, cnt5=0;
    int x = n;
    while (!(x % 2))//2的个数
    {
        cnt2++;
        x /= 2;
    }
    while (!(x% 5))//5的个数
    {
        cnt5++;
        x /= 5;
    }
    //补2或者5
    while (cnt2 > cnt5 && m / 5)
    {
        cnt2--;
        m /= 5;
        n *= 5;
    }
    while (cnt2 < cnt5 && m / 2)
    {
        cnt5--;
        m /= 2;
        n *= 2;
    }
    int res = 1;
    //补10
    for (int i = 10; i <= 1e9; i*=10)
    {
        if (m <= i)
        {
            res =i/10;
            break;
        }
    }
    //倍数
     res = m / res * res;
    cout <<res*n << endl;
}
signed main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值