HDU - 3988 Harry Potter and the Hide Story

STM32移植u8g2库(HAL库)(硬件SPI)(sh1106_128x64) STM32移植u8g2库(HAL库)(硬件SPI)(sh1106_128x64) MCU型号为STM32F103RCT6,OLED屏为中景园电子1.3寸屏,驱动芯片为sh1106,分辨率为128x64,MDK版本为V5.34。 阅读详情

题目:


1. 1 <= T <= 500 
2. 1 <= K <= 1 000 000 000 000 00 
3. 1 <= N <= 1 000 000 000 000 000 000 

思路:

对k进行质因子分解,对于每一个质因子pi,k中出现的次数为cnt,计算出n!中包括该质因子的个数sum,那么对于pi的最大值就应该是sum/cnt。

当k=1时,答案是inf

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f

const int maxn=1e7+5;
bool isprime[maxn];
int prime[maxn],tol;
void make_prime(int n){
    for(int i=0;i<=n;i++)
        isprime[i]=true;
    isprime[0]=isprime[1]=false;
    tol=0;
    for(int i=2;i<=n;i++){
        if(isprime[i])
            prime[tol++]=i;
        for(int j=0;j<tol;j++){
            if(i*prime[j]<=n)
                isprime[i*prime[j]]=false;
            else
                break;
            if(i%prime[j]==0)
                break;
        }
    }
}
LL get_sum(LL n,LL p){
    LL sum=0;
    while(n){
        n/=p;
        sum+=n;
    }
    return sum;
}
int main(){

    int T,cas=0;
    LL K,N;
    make_prime(maxn-1);
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld",&N,&K);
        if(K==1){
            printf("Case %d: inf\n",++cas);
            continue;
        }
        LL ans=-1;
        for(int i=0;i<tol&&(LL)prime[i]*prime[i]<=K;i++){
            if(K%prime[i]==0){
                LL cnt=0;
                while(K%prime[i]==0){
                    cnt++;
                    K/=prime[i];
                }
                LL tmp=get_sum(N,(LL)prime[i])/cnt;
                if(ans==-1)
                    ans=tmp;
                else
                    ans=min(ans,tmp);
            }
        }
        if(K>1){
            LL tmp=get_sum(N,K);
            if(ans==-1)
                ans=tmp;
            else
                ans=min(ans,tmp);
        }
        printf("Case %d: %lld\n",++cas,ans);
    }
    return 0;
}


YOLOv8交通管理 详细解释及代码完整示例 YOLOv8在交通管理中的应用及代码实现 摘要:本文详细介绍了YOLOv8在交通管理领域的应用场景,包括车辆检测、违规行为识别和行人安全预警等。文章提供了完整的Python代码示例,展示了如何使用YOLOv8进行交通对象检测和车辆计数统计。代码包含模型加载、对象检测、结果可视化等功能模块,并给出了性能优化和功能扩展建议。该实现基于Ultralytics框架,支持多种YOLOv8模型选择,可根据实际需求调整模型大小和检测参数。 阅读详情

相关推荐

Linux下安装FastDFS及生成缩略图

1. 安装编译环境 yum install git gcc gcc-c++ make automake vim wget libevent -y 2. 安装libfastcommon基础库 mkdir /root/fastdfs cd /root/fastdfs git clone https://github.com/happyfish100/libfastcommon.git --depth 1 cd libfastcommon/ ./make.sh && ./make.sh ins

weixin_45234710的博客 1378

[数论] hdu 3988 Harry Potter and the Hide Story

题意: 给N、K,问满足 n!%(k^x)=0 最大的x。 思路: 首先当k=1的时候,输出inf 然后就是,因为要整除,所以我们就分解k的质因子 假设每个质因子有si个,那么对应的n!里面有sumi个 那么对于当前因子最大的x=suni/si 然后就是所有的因子找最小值了。 这里需要打表 10^7的素数表 代码: #include"cstdlib" #include"cstd

Enmity_Dark 893

PyCharm启动报错急救指南:3步定位.vmoptions文件位置(Win/Mac路径详解)

本文针对PyCharm启动失败问题,提供了一份详细的急救指南。核心在于精准定位并修复关键的.vmoptions配置文件。文章通过三步法详解了在Windows和macOS系统上查找该文件的具体路径,并分析了因新旧版本冲突、破解补丁残留或参数设置错误导致启动失败的常见场景及解决办法,帮助开发者快速恢复IDE的正常工作。

weixin_28835789的博客 706

HDU - 3988 Harry Potter and the Hide Story 题解 数论

早该写了。

达瓦里希,这里禁喵。 892

交换机背板带宽、交换容量与包转发率到底是啥?

在网络工程中,交换机是核心设备之一,而关于它的性能指标,背板带宽、交换容量、以及包转发率往往成为人们衡量其性能的重要参数。这些术语的定义、关系、以及在实际场景中的应用,都对交换机的选型与部署有着重要意义。本文将为您全面解读这些概念,帮助您深入了解交换机的核心性能指标。

网络技术联盟站 1556

Cadence PCB仿真使用Allegro PCB SI S参数配置方法图文教程

S参数即S-Parameter是指散射参数,描述信号在传输线中的正反向传输和正反向反射的情况。本文讲述在使用Allegro PCB SI进行信号完整性仿真前,S参数的配置方法。

fydar的博客 2182

HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)

Harry Potter and the Hide Story Problem Description iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough. Input ...

weixin_30515513的博客 154

MTK Meta ISP 工具使用技巧与参数读取路径全解析

在联发科(MediaTek, MTK)平台上进行相机图像调试时,Meta ISP 工具是连接 PC 与设备进行参数调整、寄存器读取和图像输出的重要工具。本文以实战角度出发,系统梳理 Meta ISP 的使用流程、关键模块功能、典型调试技巧与参数读取路径,结合最新版平台(如MTK Genio/Dimensity 系列)架构,帮助工程师掌握联发科图像调优的核心流程。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 1163

HDU 3988 数论

考察的知识点很简单,就是分解质因数,和求出阶乘内某个质因子的个数。 分解完质因子后,记录下每个质因子的个数,然后计算阶乘内该因子的个数,所有的求完后即可得到答案 /* ID: CUGB-wwj PROG: LANG: C++ */ #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;list&gt; #include ...

java开发指南博客 【转载】 159

OTFS 消息传递算法信号检测【附matlab代码详解】

OTFS 消息传递算法方面的一些浅浅理解。

Cuby的博客 4015

十七、SAP-采购订单(STO)

业务逻辑、功能讲解、图文解析、章节总结

m0_72403327的博客 2074

hdu3988 Harry Potter and the Hide Story(数论-勒让德定理-质因子分解)

题意 给出一个n,一个k,求k的最大次方ans,能被n!整除 思路来源 http://www.cnblogs.com/toyking/p/3893157.html 题解 先预处理1e7以内的素数,O(nlognlogn) 每个k,对素数表里跑一遍, 这样素数枚举的时候,O(T·cnt),就不是O(T·sqrt(k))了 剩下的操作,和今晚的上个题相同(见上篇UVA-10780)...

小衣同学的博客 515

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

HDU 3988 Harry Potter and the Hide Story【数论】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3988 题目大意:给定n,kn,kn,k,找到最大的iii满足{i∣ki  divides  n!}\{i|k^i \ \ divides \ \ n!\}{i∣ki  divides  n!}。kkk数据范围1e141e1...

weixin_43499182的博客 202

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

hdu 3988 Harry Potter and the Hide Story (素因子)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3988 题意:给出n,k,找出最大的i,满足 n!%k^i。 题解:我们先对k进行质因子分解,假设p是k的一个质因子,那么我们先算出p在k中出现的次数tt,然后算出在n中出现的次数num,此时i 最大为num/tt,故我们就一直找k的质因子,每次取 num/tt的最小值。 代码: #i...

Jiandong 297

HDU 3988 Harry Potter and the Hide Story (数论)

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 该回到老本行,继续数学类学习,在这之前先做些题复习复习 这是一个多校题目。求最大的i使得n!%k^i为0。竟然能够整除,那说明k的质因子都会出现在n!中才行。 首先对k进行质因子分解,对于每一个质因子,k中出现的次数为c,而

窝不是爱酱,喵~~~~ 1588

HDU3988 Harry Potter and the Hide Story

首先对K进行素因子分解,分解成:p1^r1 * p2^r2*...pk^rk. 然后求出n!含有的K的因子pi的个数,把这个数除以ri得到一个值,取这个值最小值就是答案. #include #include #include using namespace std; #define INF 9223372036854775807LL const int MAX = 10000050;

蚂蚁大战大象 682

HDU 3988 Harry Potter and the Hide Story

Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2934    Accepted Submission(s): 755 Problem Descripti

wings的博客 377

hdu 3988 Harry Potter and the Hide Story

#include #define MAX 10000000 #define PRIME 700000 #define INF 9223372036854775807LL using namespace std; long long m,n,ans; bool isprime[MAX+10]; long long prime[PRIME+10],top=0; void init()

South__wind的专栏 498

HDU 3988 Harry Potter and the Hide Story(数论)(素数筛法)

Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2734    Accepted Submission(s): 688 Problem Description

huatian5的博客 861

解题报告:HDU_3988 Harry Potter and the Hide Story 大素数分解+勒让德

Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2836    Accepted Submission(s): 720 Problem Description

Hee的博客~ 394

HDU 3988 Harry Potter and the Hide Story——唯一分解定理

题意: 给定n和k,求一个最大的x,使得n! % k ^ x == 0 思路: 打出素数表,用每个素数分解n!和k,得到y和x,ans = min(ans,y/x) 对m!阶乘唯一分解可以写作: while (m) {                 m /=prime[i];                 y += m;             } 类似于统计m以内有多少个p...

hao_zong_yin的博客 518

HDU 3988-Harry Potter and the Hide Story(分解素数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3988 大致题意:给定n和k,求n!%k^i==0 的i最大等于多少 题目思路:对k做素数分解,然后看它在n!中相应的素数的指数,从而求出i的最大值 #include #include #include #include #include #includ

信仰.的博客 621

Harry Potter and the Hide Story(hdu3988)

Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2809Accepted Submission(s): 715 Problem Description ...

weixin_30685029的博客 89

Harry Potter and the Hide Story HDU - 3988 (数论)

iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough. Input The first line contains a single integer T, indicating the number of test cases. E

Coldfresh的博客 426

HDU3988-Harry Potter and the Hide Story(数论-质因数分解)

Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2193    Accepted Submission(s): 530 Problem Descripti

mowayao的专栏 936
上一篇: POJ - 2689 Prime Distance 素数筛
下一篇: POJ - 1095 Trees Made to Order 卡特兰数+递归
我不会额
博客等级 码龄11年 2粉丝 173原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值