UVA11802-All Your Bases Belong to Us
来源:互联网 发布:淘宝代运营公司诈骗 编辑:程序博客网 时间:2024/06/04 18:24
All Your Bases Belong to Us
It is very easy to find number of trailing zero in n! for a
particular base b. In this problem you have to do the reverse.
You have to find for how many bases b, n! has k trailing zeros
in base b.
Input
Input starts with a positive number T ≤ 10000, denoting the
number of test cases to follow.
Each test case contains two non-negative integers, n ≤
1015 and 1 ≤ k ≤ 1015 in a line. You may assume that n/k < 500.
Output
For each input output one line containing the number of different bases. Print the solution modulo
1000000007
Sample Input
5
10 2
10 3
10 4
10 5
10 8
Sample Output
Case 1: 24
Case 2: 0
Case 3: 4
Case 4: 0
Case 5: 1
题目大意:给定n,k。求有多少个b满足在b进制下
数据范围:
解题思路: 设
则所求结果为
因为
又因为
那么对于质因数
通过求
结合数据范围,
所以可以筛选出501以内的素数,记录
所以
所以
利用乘法原理即可求出b的个数
#include<iostream>#include<cstdio>#include<vector>#include<cstring>#include<queue>using namespace std;typedef long long LL;const int MAXN=505;const LL mod=1000000007;int prime[MAXN];LL pownum[MAXN];LL n,k;int bound;void getprime()//素数筛选{ memset(prime,0,sizeof(prime)); for(int i=2;i<=MAXN;i++) { if(!prime[i]) prime[++prime[0]]=i; for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++) { prime[prime[j]*i]=1; if(i%prime[j]==0) break; } }}//对于某数b,n!|b^k的b的个数LL fun(LL k){ LL ans=1; for(int i=1;i<=bound;i++) { ans*=(pownum[i]/k+1);//乘法原理 ans%=mod; } return ans;}LL cal(int i)//求n!含有prime[i]的个数{ LL exp=0; LL tmp=n; while(tmp) { tmp/=prime[i]; exp+=tmp; } return exp;}int main(){ ios::sync_with_stdio(false); getprime();// cout<<prime[0]<<endl;// for(int i=1;i<=96;i++)// {// cout<<prime[i]<<" ";// if(i%10==0) cout<<endl;// } int T; cin>>T; int cas=0; while(T--) { cin>>n>>k; for(int i=1;i<=96;i++)//503 第96个素数 { pownum[i]=cal(i); if(pownum[i]<k) { bound=i-1; break; } } cout<<"Case "<<++cas<<": "<<((fun(k)-fun(k+1)%mod+mod))%mod<<endl; } return 0;}
- UVA11802-All Your Bases Belong to Us
- 2005-11-19 15:11love,not belong to us
- 2005年11月19日 15时6分love,not belong to us
- Error:All flavors must now belong to a named flavor dimension
- 解决 Error:All flavors must now belong to a named flavor dimension
- Error:All flavors must now belong to a named flavor dimension. The flavor 'flavor_name' is ...
- 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- 《android日常bug系列》as升级3.0后报错,All flavors must now belong to a named flavor dimension.
- Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- android studio3.0——Error:All flavors must now belong to a named flavor dimension. Learn more at ...
- Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r
- 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r
- 解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
- All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tool
- Your database instance is running with full workload after database creation. You have decided to us
- Your Progress As A Programmer Is All Up To You
- App启动加载广告页面思路
- Oracle中的SQL分页查询原理和方法详解
- 12_opengl学习
- gulp 安装 gulp-css-spriter
- 【python学习笔记】Dataframe和类SQL的merge函数(一)
- UVA11802-All Your Bases Belong to Us
- Class org.apache.struts2.json.JSONWriter can not access a member of class
- 微信图片预览的小经验
- mui框架 页面无法滚动解决方法
- hive安装过程全程解析、hive常规操作、说明
- 最不擅长等分布局
- hive UDF实操及解析说明
- iOS 简单工厂模式、抽象工厂模式~详解
- 关于phantomjs evaluate沙盒环境的点击事件