Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解
来源:互联网 发布:柏原崇 知乎 编辑:程序博客网 时间:2024/05/22 14:20
传送门:点击打开链接
A. k-rounding
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputFor a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the k-rounding of n.
Input
The only line contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 8).
Output
Print the k-rounding of n.
Examples
input
375 4
output
30000
input
10000 1
output
10000
input
38101 0
output
38101
input
123456789 8
output
12345678900000000
找到前一个数的倍数,满足后缀有K个0,输出最小的那个数。刚开始是暴力,一一枚举n的倍数,后来发现第四组示例跑死了啊,4秒才出结果,12345678900000000实在是太大了,只好换别的方法,又想到单独处理质数,然后合数求GCD试试,后来发现为什么要单独判断质数呢?直接全部GCD就OK了。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=100005;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int main(){ll n,k,i,flag;while(cin>>n>>k){ll temp=fpow(10ll,k);ll ans=gcd(n,temp);cout<<temp/ans*n<<endl;}return 0;}
阅读全文
0 0
- Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) C
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) D
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1) ABCDF
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A-C
- Codeforces Round #445 (Div. 1, based on Technocup 2018 Elimination Round 3) E. Mod Mod Mod
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) C
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #380 (Div. 2,Based on Technocup 2017 - Elimination Round 2)C - Road to Cine//
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) 总结
- Codeforces Round #445 (Div. 2, based on Technocup 2018 Elimination Round 3)
- hdu 2057 A + B Again
- UE4 安卓打包
- 动态加载布局
- 保留一份数据源的配置druid
- n位数,去除m位,获得最大的值
- Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解
- 深入java 定义正则表达式
- 互联网协议入门(二)
- Spring整合Mybatis实现动态数据源切换教程配置
- Android Studio 项目中,忽略文件不提交
- TCP和UDP的区别
- 素数计数函数
- Tensorflow学习之卷积神经网络实现(六)
- H5性能优化方面的探索