/*
* url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1080
* stratege: 将除数m进行分解,分别求出质因子及其个数,然后对n进行判断,n中是否包含m的每个质因子下的个数,如果有,则可整除
* Test Case: 16 32768 yes, 32768 = 2^15, 16!包含15个因子2,可整除
* Status: 10537360 10139 Factovisors Accepted C++ 2.820 2012-08-29 07:45:15
* Author: johnsondu
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std ;
#define LL long long
const int MAXN = 50000 ;
bool isPrime[MAXN] ;
int p[MAXN], prilen ;
bool flag ;
LL n, m ;
LL f[35][2], flen ;
void getPrime () //筛选素数
{
int i ;
memset (isPrime, true, sizeof (isPrime)) ;
isPrime[0] = isPrime[1] = false ;
for (i = 4; i < MAXN; i += 2)
isPrime[i] = false ;
p[0] = 2, prilen = 1 ;
for (i = 3; i < MAXN; i += 2)
{
if (isPrime[i])
{
p[prilen ++] = i ;
for (int j = 2*i; j < MAXN; j += i)
isPrime[j] = false ;
}
}
}
void divide ()
{
flen = 0 ;
LL i, tp = m ;
memset (f, 0, sizeof (f)) ;
for (i = 0; (LL)p[i]*p[i] <= tp; i ++)
{
if (tp % p[i] == 0)
{
f[flen][0] = p[i] ; //保存质因子
while (tp % p[i] == 0)
{
f[flen][1] ++ ; //该质因子下的数量
tp /= p[i] ;
}
flen ++ ;
}
}
if (tp == m && n < m)
{
flag = true ;
}
if(tp > 1)
{
f[flen][0] = tp ;
f[flen][1] = 1 ;
flen ++ ;
}
}
void solve ()
{
flag = false ;
divide () ;
for (int i = 0; i < flen; i ++) //假设测试案例为16, 32728, 16的阶乘中有15个为2的质因子,
{
int t = (int)((log(n*1.0))/(log(f[i][0]*1.0))) ; //(1)假设m的第一个质因子为x, 则此处是求x^1, x^2, x^3,.. 一共有有p项
int tmp = t ;
int tt = 0 ;
for (int j = 1; j <= tmp-3; j ++) //比如当前质因子为2,则3*2*2 = 12也在16内,此时多一个2, 通过验算
tt += j*j ; //出现这类类似情况时,是从x^3以后开始出现,并且多出的个数为1, 4, 9,..为平方数。这里求多出的质因子的个数
t = t*(t+1)/2 ; //在(1)下,m的质因子的总和的个数,比如m为16,在(1)中求出t = 4, 则有2^1, 2^2, 2^3, 2^4, 共有10个2
t = (n/f[i][0]-tmp) + t + tt ; //(n/f[i][0]-tmp) 表示普通的能被2直接整除的个数,比如6 = 2*3, 12=2*6..
if (t < f[i][1]) //如果个数小于m中质因子的个数,显然无法整除
{
flag = true ;
break ;
}
if (flag)
break ;
}
if (flag)
printf ("%lld does not divide %lld!\n", m, n) ;
else printf ("%lld divides %lld!\n", m, n) ;
}
int main ()
{
getPrime () ;
while (scanf ("%lld%lld", &n, &m) != EOF)
{
if (m < MAXN)
{
if (isPrime[m] && n < m)
{
printf ("%lld does not divide %lld!\n", m, n) ;
continue ;
}
}
if (m == 0)
{
printf ("%lld does not divide %lld!\n", m, n) ;
continue ;
}
if (m == 1)
{
printf ("%lld divides %lld!\n", m, n) ;
continue ;
}
solve () ;
}
return 0;
}
相关推荐
机器学习模型——非线性回归
升维是一种常用的处理非线性问题的方法,它通过将原始数据从低维空间映射到高维空间来增强模型的表达能力。我们可以看出,二维数据用一维直线很难去很好的拟合。升维里的degree设置的不易过大,否则容易造成维度灾难。升维后,拟合的线与原数据比较符合。将非线性问题转换为线性问题。
UVa 10139 - Factovisors
题目:判断n!能否整除m。 分析:数论。先将m拆成素数的积的形式,再判断n!中对应每个素数的个数,是否大于m的即可。 首先,打表计算50000内素数,用这些素数除不尽的数一定也是素数,不过最多只有一个; 然后,分解m成素数的积的形式,统计每个素数因子的个数; 最后,判断n!中每个素数因子的个数是否大于m中对应的素数个数
FPGA 上的 YOLOv8 实时目标检测:从模型优化到硬件加速全解析
本文全面解析了将YOLOv8目标检测模型部署到FPGA进行硬件加速的完整流程。通过模型裁剪、混合精度量化等优化手段,结合HLS设计专用计算引擎与数据流,实现了高能效比的实时推理。文章深入探讨了软硬协同部署、性能调试与优化技巧,为追求极致实时性与低功耗的边缘AI应用提供了从算法到硬件的实战指南。
uva 10139 factovisors
Problem D: Factovisors The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n > 0) We say that a divides b if there exists an integer k such tha
深入解析Unity3D中PostLateUpdate突然占用大量时间的原因
在Unity3D的生命周期中,是一个在LateUpdate之后被调用的方法。它通常用于处理一些需要在所有更新(包括物理更新和动画更新)之后进行的逻辑。由于它在游戏循环的后期阶段被调用,因此它通常用于处理与渲染直接相关的任务,如相机调整、UI更新等。突然占用大量时间的问题可能由多种原因引起,包括复杂的逻辑处理、频繁的资源加载、不恰当的渲染优化、插件或第三方库的副作用以及内存泄漏或垃圾回收等。为了解决这个问题,开发者需要仔细审查和优化中的代码,同时利用Unity提供的工具来监控和分析游戏性能。
systermverilog中for循环中的fork join执行情况分析
仅为本人学习记录,如有错误感谢指正!
UVa 10139 Factovisors
/* File: 10139.cpp Author: ACboy Date: 2010-4-22 Result: AC Descripition: UVa 10139 Factovisors*/#include #include #include #include using namespace std;map m;set s;/
Stata实战:DID平行趋势检验完整操作指南(附reghdfe+coefplot代码)
本文提供了一份使用Stata进行DID平行趋势检验的完整实战指南。文章详细讲解了从数据准备、生成相对时间变量,到利用reghdfe命令构建动态效应模型,以及使用coefplot命令进行结果可视化的全流程操作。核心在于通过检验政策前交互项的显著性,验证处理组与对照组是否满足平行趋势假设,为后续因果推断奠定可靠基础。
UVa 10139 Factovisors (阶乘能否整除?)
10139 - Factovisors Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1080 水题。 注意在O(log n / log p)时间内求出n!
属性基加密(Attribute-based Encryption, ABE)
KP-ABE中,用户的密钥定义了访问策略,密文的属性与策略进行匹配。CP-ABE中,密文定义了访问策略,用户的属性与策略进行匹配。
IEEE Journal of Biomedical and Health Informatics(JBHI)投稿经验分享
《IEEE Journal of Biomedical and Health Informatics投稿经验分享》详细记录了在影响因子6.7的中科院一区期刊JBHI的投稿历程(2025.1-5月,历时4个月)。文章重点分析:1)审稿特色:4位审稿人差异显著,领域专家意见专业但要求严苛;2)修改要点:需重视大修(补充实验/原理阐述),并注意将回复内容同步至正文;3)期刊特点:送审率高但审稿严格,常规投稿周期约4-5个月;4)实用建议:建议首次大修全力以赴,善用AI工具辅助写作,避免拖延。
Factovisors - PC110704
原创: 作者:MilkCu 题目描述 Problem D: Factovisors The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n > 0) We say that a divides b if there exis
基于Solidworks的三维光路结构示意图绘制实例演示-技术细节
基于Solidworks的三维光路结构示意图绘制实例演示-技术细节
UVA 10139 Factovisors
一道数论题,题意大致是判断一个数m是不是另一个数n的阶乘的因子。判断其实也非常的简单就是看m的因子的的个数是否多于n的阶乘中相应的因子的个数;而计算n的阶乘中因子p的个数由一个算法计算代码如下int Cal(int w, int p) //计算w的阶乘中有多少个p { int ans = 0; while(w) { w /= p; ans +
Probability and Statistics - 4th edition
Probability and Statistics - 4th edition
IMSL CNL 7.0.0 (x86-64)Crack
IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件
UVa Problem Solution: 10139 - Factovisors
We check each of the prime factors of m to see if n! has enough prime factors of the same value. If so, m can divide n!, otherwise m can not divide n!.Code:/*******************************************
TMS_WebGMaps_1.9.8.0_Full_Source
TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder
UVA 10139 Factovisors(数论)
Factovisors The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n > 0) We say that a divides b if there exists an integer k such that k*a =
最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版
Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。
UVa Problem 10139 Factovisors (阶乘与整除)
// Factovisors (阶乘与整除)// PC/UVa IDs: 110704/10139, Popularity: A, Success rate: average Level: 2// Verdict: Accepted// Submission Date: 2011-06-11// UVa Run Time: 0.312s//// 版权所有(C)2011,邱秋。met
【 UVa 10139】 Factovisors 【 m | n!? 】
分析 由唯一分解定理,我们可知道 m=p1^r1*p2^r2……pn^rn (p为素数)。 如果n!要想被m整除,必须也至少有 p1^r1*p2^r2……pn^rn 。 另外 注意在O(log n / log p)时间内求出n!的质因子分解中质数p的指数:(勒让德定理的简化算法)inline int getn(int n, int p) { int sum = 0;
[UVA10139]Factovisors(数论,质因数)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1080 题意:问n!能否被m整除。 给m分解质因数,用这些质因数以及他们的幂分别去除n,直到质因数的幂大于n。统计每一次的商,假如存在一个商小于质因数在m中出现的次数,...
POJ2649 ZOJ1850 UVA10139 Factovisors【筛选法+勒让德定理】
FactovisorsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4511 Accepted: 1116DescriptionThe factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)...
PC/UVa 题号: 110704/10139 Factovisors
两个数 n 和 k 判断k能否整除 n! 思路: 任何一个正整数 n=p1^(x1)*p2^(x2)……*pn^(xn); 其中p1,p2.……pn 是素数,x1,x2,……xn 是各个素数的指数(也就是该质因数的个数) 将k分解质因数,并记录各个质因数的个数 分别用 2……n的数去除以k的质因数,每除一次就使k的质因数的个数减一,直到为零,最后遍历记录k的质因数个数的数组,只要有大于零的
1428



被折叠的 条评论
为什么被折叠?



