LightOJ 1340 - Story of Tomisu Ghost 阶乘分解素因子
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 阶乘分解素因子的更多相关文章
- 1340 - Story of Tomisu Ghost
1340 - Story of Tomisu Ghost PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- 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 ...
- 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m
给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...
- 数论-质数 poj2689,阶乘分解,求阶乘的尾零hdu1124, 求尾零为x的最小阶乘
/* 要求出[1,R]之间的质数会超时,但是要判断[L,R]之间的数是否是素数却不用筛到R 因为要一个合数n的最大质因子不会超过sqrt(n) 所以只要将[2,sqrt(R)]之间的素数筛出来,再用这 ...
- luogu1445 [violet]樱花 阶乘分解
题目大意 求方程$$\frac{1}{x}+\frac{1}{y}=\frac{1}{N!}$$的正整数解的组数. 思路 咱们把式子整理得$$xy-(x+y)N!=0$$.$xy$和$x+y$?貌似可 ...
- 给定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均为正整 ...
- FZU OJ 1075 :分解素因子
Problem 1075 分解素因子 Accept: 2161 Submit: 4126Time Limit: 1000 mSec Memory Limit : 32768 KB Pro ...
- fuzhou 1075 分解素因子
Problem 1075 分解素因子 Accept: 1331 Submit: 2523Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FZU 1075 分解素因子【数论/唯一分解定理/分解素因子裸模板】
[唯一分解定理]:https://www.cnblogs.com/mjtcn/p/6743624.html 假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个 ...
随机推荐
- BZOJ 1503 郁闷的出纳员(平衡树)(NOI 2004)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作 ...
- Tic-Tac-Toe
Description Kim likes to play Tic-Tac-Toe. Given a current state, and now Kim is going to take his n ...
- win10 死机
其实Win10系统还是不错的,如果你的电脑升级Win10后中招经常死机,可以用下面的方案来应对. 1.下载安装支持兼容Win10的软件版本,下载软件之前看一下兼容列表里是否有Win10系统.虽然Win ...
- C++ 学习笔记之 引用
一.定义: 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样. 二.用法: 基本用法 例如: int & a = b; 引用作为函数返回值 先看一个例子: #inclu ...
- iOS- 如何将非ARC的项目转换成ARC项目(实战)
1.前言 因为公司有个国外餐饮系统,编程开发了3-4年,之前用的都是非ARC,开发到今年,第一批迭代开发的人员早已不见,目前发现了有许多的内存泄露之类的,系统没有自动释放该释放的内存.一旦app长 ...
- 老生常谈-从输入url到页面展示到底发生了什么
来自:咸鱼老弟 - 博客园 链接:http://www.cnblogs.com/xianyulaodi/p/6547807.html
- Code Quality
Code Quality https://www.sonarqube.org/ java https://www.sonarsource.com/products/codeanalyzers/sona ...
- MyBatis原理简介
1.什么是 MyBatis ? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyB ...
- IE8 兼容CSS3 使用 PIE.htc
在需要的标签中 div { border:; border-bottom: 10px solid transparent; border-image: url(../images/border-img ...
- iOS-开发中的时间处理
做App避免不了要和时间打交道,关于时间的处理,里面有不少门道,远不是一行API调用,获取当前系统时间这么简单.我们需要了解与时间相关的各种API之间的差别,再因场景而异去设计相应的机制. 时间的形式 ...