http://www.lightoj.com/volume_showproblem.php?problem=1340

题意:问n!在b进制下至少有t个后缀零,求最大的b。

思路:很容易想到一个数通过分解素因子可以得到最大的指数。那么问题关键在于求得n!的素因子的指数,找到指数大于t的所有素因子,再将那些指数除去t,剩下的数就是最大的b了。分解阶乘时,对n不断除素数p,直到n为0时,此时商的和即该素因子的指数。

/** @Date    : 2016-11-30-19.35
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/ #include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+2000;
const int mod = 10000019;
LL pri[N];
int c = 0;
bool vis[N]; void prime()
{
for(int i = 2; i < N; i++)
{
if(!vis[i])
{
for(int j = i + i; j < N; j+= i)
{
if(!vis[j])
vis[j] = 1;
}
pri[c++] = i;
}
}
} LL fpow(LL a, LL n)
{
LL r = 1;
while(n > 0)
{
if(n & 1)
r = r * a % mod;
a = a * a % mod;
n >>= 1;
}
return r;
} int main()
{
prime();
int T;
int cnt = 0;
cin >> T;
while(T--)
{
LL n;
LL r;
cin >> n >> r;
LL ans = 1;
for(int i = 0; i < c && pri[i] <= n; i++)
{
LL t = n;
LL ct = 0;
while(t)
{
ct += t / pri[i];
t /= pri[i];
}
if(ct >= r)
ans = ans * fpow(pri[i], ct/r) % mod;
if(ct < r)
break;
}
if(ans == 1)
printf("Case %d: -1\n", ++cnt);
else
printf("Case %d: %d\n", ++cnt, ans);
}
return 0;
}

LightOJ 1340 - Story of Tomisu Ghost 阶乘分解素因子的更多相关文章

  1. 1340 - Story of Tomisu Ghost

    1340 - Story of Tomisu Ghost   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  2. BNU 13259.Story of Tomisu Ghost 分解质因子

    Story of Tomisu Ghost It is now 2150 AD and problem-setters are having a horrified time as the ghost ...

  3. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m

    给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...

  4. 数论-质数 poj2689,阶乘分解,求阶乘的尾零hdu1124, 求尾零为x的最小阶乘

    /* 要求出[1,R]之间的质数会超时,但是要判断[L,R]之间的数是否是素数却不用筛到R 因为要一个合数n的最大质因子不会超过sqrt(n) 所以只要将[2,sqrt(R)]之间的素数筛出来,再用这 ...

  5. luogu1445 [violet]樱花 阶乘分解

    题目大意 求方程$$\frac{1}{x}+\frac{1}{y}=\frac{1}{N!}$$的正整数解的组数. 思路 咱们把式子整理得$$xy-(x+y)N!=0$$.$xy$和$x+y$?貌似可 ...

  6. 给定n,求1/x + 1/y = 1/n (x<=y)的解数~hdu-1299~(分解素因子详解)

    链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...

  7. FZU OJ 1075 :分解素因子

    Problem 1075 分解素因子 Accept: 2161    Submit: 4126Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pro ...

  8. fuzhou 1075 分解素因子

    Problem 1075 分解素因子 Accept: 1331    Submit: 2523Time Limit: 1000 mSec    Memory Limit : 32768 KB Prob ...

  9. FZU 1075 分解素因子【数论/唯一分解定理/分解素因子裸模板】

    [唯一分解定理]:https://www.cnblogs.com/mjtcn/p/6743624.html 假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个 ...

随机推荐

  1. 编译安装hadoop2.6.3

    一.安装环境 1.1  JAVA  安装java1.7 下载jdk1.7: [root@node1~]# wget http://download.oracle.com/otn-pub/java/jd ...

  2. HDU 2485 Destroying the bus stations(!最大流∩!费用流∩搜索)

    Description Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “im ...

  3. 2018-9-25kanboard安装及使用

    2018-9-25kanboard安装及使用 教程 小书匠  欢迎走进zozo的学习之旅. 简介 运行官方docker容器 使用kanboard 简介 Kanboard的安装提供了两种方式一种是直接安 ...

  4. 团队作业7——第二次项目冲刺(Beta版本)

    团队作业7——第二次项目冲刺-Beta版本项目计划 团队作业7——第二次项目冲刺(Beta版本)-第一篇 团队作业7——第二次项目冲刺(Beta版本)-第二篇 团队作业7——第二次项目冲刺(Beta版 ...

  5. LintCode-67.二叉树的中序遍历

    二叉树的中序遍历 给出一棵二叉树,返回其中序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 返回 [1,3,2]. 挑战 你能使用非递归实现么? 标签 递归 二叉树 二叉树遍历 code /** ...

  6. Debian常用软件

    1. 有道词典 https://github.com/justzx2011/openyoudao

  7. week1 技术随笔

    类别c 内容c 开始时间s 结束时间e 被打断时间I 总计(min) 9.5 随笔 构建之法福后感 22:00 24:00 7 113 9.6 分析 需求分析 9:00 9:30 2 28 编码 词频 ...

  8. (转)Elasticsearch .net client NEST使用说明 2.x

    Elasticsearch.Net与NEST是Elasticsearch为C#提供的一套客户端驱动,方便C#调用Elasticsearch服务接口.Elasticsearch.Net是较基层的对Ela ...

  9. 利用FluidMoveBehavior制作出手机通讯录平滑的效果

    最近学习Blend,原来Blend制作动画等效果非常棒.下面演示一下FluidMoveBehavior应用,利用Blend中行为中的FluidMoveBehavior制作出手机通讯录平滑的效果 1.在 ...

  10. 简易js调试

    1.console显示信息的命令: console.log()  console.info()  console.error()   console.warn() 2.console信息分组 cons ...