Again Prime? No time.
Input: standard input
Output: standard output
Time Limit: 1 second

The problem statement is very easy. Given a
number n you have to determine the largest power
of m, not necessarily prime, that
divides n!.

Input

The input file consists of several
test cases. The first line in the file is the number of cases to handle. The
following lines are the cases each of which contains two integers m
(1<m<5000)
and n
(0<n<10000)
. The integers are separated by an space. There
will be no invalid cases given and there are not more
that500 test cases.

Output

For each case in the input, print
the case number and result in separate lines. The result is either an integer
if m divides n! or a line
"Impossible to divide" (without the quotes). Check the
sample input and output format.

Sample
Input

2
2 10
2
100

Sample
Output

Case 1:
8
Case 2:
97

题意:求N!%M^k==0;最大的k;

思路:先算M的质因子m,并保存质因子的个数,从N开始递减到N/m,计算每个质因子在N!中出现的次数,取最小。

一开始我的思路是取最大的质因子,然后发现错了,然后想是质因子*个数最大的那个,然后想了下40,100就不对了。所以就把所有的质因子都算了一次。(本来以为会超时。。。结果142ms过。o(︶︿︶)o
唉)

转载请注明出处:寻找&星空の孩子

题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=77956#problem/E

 #include<stdio.h>
#include<string.h>
#define LL long long
/*
bool prime(int x)
{
for(int i=2;i*i<=x;i++)
{
if(!(x%i)) return 0;
}
return 1;
}*/
LL a[];
inline void Maxprime(LL x)
{
LL t=,k=;
for(LL i=; i<=x; i++)
{
while(x%i==)
{
t=i;
a[i]++;
x/=i;
}
}
if(t==)
{
a[x]=;
}
}
inline LL Ssum(LL x)
{
return (x*(x+))/;
}
LL Sumprime(LL x,LL mod)
{
LL t=;
while(x)
{
if(x%mod==) t++,x/=mod;
else return t;
}
return ;
} int main()
{
LL n,m,T,caseT=;
scanf("%lld",&T);
while(caseT<=T)
{
memset(a,,sizeof(a));
// memset(b,0,sizeof(b));
scanf("%lld%lld",&m,&n);
LL mod;
Maxprime(m);
/* if(mod!=m)
{
LL tt=0;
for(LL i=2;i<n;i++)
{
if(tt<i*a[i])
{
tt=i*a[i];
mod=i;
}
}
}*/
// printf("mod=%d\n",mod); LL sum,minsum=;
for(LL j=; j<=m; j++)
{ if(!a[j]) continue;
sum=;
for(LL i=n; i>n/j; i--)
{
LL tmp=Sumprime(i,j);
if(tmp) sum+=Ssum(tmp);
}
if(minsum>sum/a[j]) minsum=sum/a[j];
}
printf("Case %lld:\n",caseT++);
if(!sum) printf("Impossible to divide\n");
else printf("%lld\n",minsum);
}
return ;
}

Again Prime? No Time.(uva10870+数论)的更多相关文章

  1. UVA10140 Prime Distance【素数/数论】By cellur925

    题目传送门 我们注意到,L,R是肥肠大的.........我们不可能在1s内筛出2^31内的全部质数. “上帝为你关上一扇门,同时为你打开一扇窗” 我们又注意到,R-L是肥肠比较小的,珂以从这入手解决 ...

  2. 【HDU】2866:Special Prime【数论】

    Special Prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. POJ 1365 Prime Land(数论)

    题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime ...

  4. 数论 - Miller_Rabin素数测试 + pollard_rho算法分解质因数 ---- poj 1811 : Prime Test

    Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 29046   Accepted: 7342 Case ...

  5. 数论 - 素数的运用 --- poj 2689 : Prime Distance

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12512   Accepted: 3340 D ...

  6. UVA 11610 Reverse Prime (数论+树状数组+二分,难题)

    参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...

  7. codeforces 680C C. Bear and Prime 100(数论)

    题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. 【斐波拉契+数论+同余】【ZOJ3707】Calculate Prime S

    题目大意: S[n] 表示 集合{1,2,3,4,5.......n} 不存在连续元素的子集个数 Prime S 表示S[n]与之前的所有S[i]互质; 问 找到大于第K个PrimeS 能整除X 的第 ...

  9. UVA 10140 - Prime Distance(数论)

    10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...

随机推荐

  1. ZKWeb网页框架2.1正式发布

    2.1.0更新的内容有 更新引用类库 NHibernate 5.1.0 Npgsql 3.2.7 MySqlConnector 0.37.0 Dapper 1.50.4 Dommel 1.10.1 Z ...

  2. 第44节:Java当中的JVM

    Java当中JVM 01 在使用控制面板时的实质: Hello.java使用javac,然后变成为Hello.class通过运行java这个命令,在类加载器中(含有加载,验证,准备,解析,初始化,使用 ...

  3. 《http权威指南》读书笔记12

    概述 最近对http很感兴趣,于是开始看<http权威指南>.别人都说这本书有点老了,而且内容太多.我个人觉得这本书写的太好了,非常长知识,让你知道关于http的很多概念,不仅告诉你怎么做 ...

  4. AI - 机器学习常见算法简介(Common Algorithms)

    机器学习常见算法简介 - 原文链接:http://usblogs.pwc.com/emerging-technology/machine-learning-methods-infographic/ 应 ...

  5. 我面试过没有上万人也有十几个,简历要这么写才有hr要你

    今天终于有时间好好给大家写写关于如何写简历,给自己加分了. 这篇文章拖了很久了应该说,本来想在上周写的,但是事情实在是太多,又不想草草了事,所以搁置到现在.今天早上正好空出来了,就马上给大家码出来了. ...

  6. remote: Incorrect username or password ( access token )

    解决问题 进入控制面板 用户账号,选择管理您的凭据 修改凭据 修改完成后,保存即可

  7. Http状态信息

    一.HTTP协议1.简介:http超文本传输协议,基于请求与响应模式的,无状态的,应用层的协议.绝大读书的web开发都是建立在http协议之上的.2.http工作过程:当请求一个超链接时,http就开 ...

  8. 技术简历这样写,才能得到BAT面试官的青睐

    公众号[程序员江湖] 作者陆小凤,985 软件硕士,阿里 Java 研发工程师,在技术校园招聘.自学编程.计算机考研等方面有丰富经验和独到见解,目前致力于分享程序员干货和学习经验,同时热衷于分享作为程 ...

  9. java扫盲 接口 Enumeration

    摘要: 摘要: 原创出处: http://www.cnblogs.com/Alandre/ 泥沙砖瓦浆木匠 希望转载,保留摘要,谢谢! 记起2年前,高中生活最多的是老师的批评.谢谢! -泥沙砖瓦浆木匠 ...

  10. 32位汇编第五讲,逆向实战干货,(OD)快速定位扫雷内存.

    32位第五讲,逆向实战干货,快速定位扫雷内存. 首先,在逆向之前,大家先对OD有一个认识. 一丶OD的使用 标号1: 反汇编窗口 (显示代码的地址,二进制指令,汇编代码,注释) 标号2: 寄存器窗口( ...