Rounding Many Ways------------------思維(套路)

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
題意:
XY=10^Z,XW=N
給定N,求有多少個X
解析:
由第一個式子可知:10的冪次的因子只有2和5
所以分解N有多少個2和多少個5,然後組合起來即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll quick(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a;
		a=a*a;
		b>>=1;
	}
	return res;
 } 
int main()
{
	scanf("%lld",&n);
	vector<ll> v;
	int a=0,b=0;
	while(n%2==0)
	{
		n/=2;
		a++;
	}
	while(n%5==0)
	{
		n/=5;
		b++;
	}
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			v.push_back(quick(2,i)*quick(5,j));
		}
	}
	sort(v.begin(),v.end());
	cout<<v.size()<<endl;
	for(ll it:v)
	{
		cout<<it<<endl;
	}

 } 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章