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

单路径微分相除和微分自乘相减算法(PGC-SDD-DSM) PGC-SDD-DSM算法通过融合单路微分相除和差分自乘,解决了传统PGC解调技术对调制深度和光强干扰敏感的问题,显著提升了解调稳定性和抗失真能力。其高信噪比、低谐波失真以及对参数变化的鲁棒性,使其在光纤传感领域具有重要应用价值。PGC-SDD-DSM算法在计算复杂度方面具有显著的优势,主要体现在其高稳定性和低谐波失真上。这些优势使其在光纤光学干涉传感器中表现出色,尤其是在面对光强干扰和调制深度变化时。 阅读详情

Harry Potter and the Hide Story

传送门(建议到 vjudge 上去提交)

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 T T, indicating the number of test cases.
Each test case contains two integers, N N N and K K K.

Technical Specification

  1. 1 ≤ T ≤ 500 1 \leq T \leq 500 1≤T≤500;
  2. 1 ≤ K ≤ 100000000000000 1 \leq K \leq 1 000 000 000 000 00 1≤K≤100000000000000;
  3. 1 ≤ N ≤ 1000000000000000000 1 \leq N \leq 1 000 000 000 000 000 000 1≤N≤1000000000000000000。

Output

For each test case, output the case number first, then the answer, if the answer is bigger than 9223372036854775807 9 223 372 036 854 775 807 9223372036854775807, output inf (without quote).

Sample

Input

2
2 2
10 10

Output

Case 1: 1
Case 2: 2

翻译

给定 N N N 和 K K K,求 n ! m o d    k i n!\mod k^i n!modki 等于 0 0 0 时, i i i 的最大取值。

解题思路

前置知识

正文

知道了勒让德定理,那就好办了。直接把 K K K 进行质因数分解,让后套勒让德定理,求出该质因子在 N ! N! N! 中的指数。最后再将这些指数求最小值即可。(就这么短)

注意:HDU 不能用万能头啊!

在这里插入图片描述

(日常派大星:1/1)

AC Code

// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define int long long
bool Mark[10000005];
int Prime_List[10000005];
int Prime_List_Length;
inline void Make_Prime_List() {
	memset(Mark,0,sizeof Mark);
	Prime_List_Length=0;
	for(register int i=2; i<=10000005; ++i) {
		if(!Mark[i])
			Prime_List[++Prime_List_Length]=i;
		for(register int j=1; j<=Prime_List_Length&&i*Prime_List[j]<10000005; ++j) {
			Mark[i*Prime_List[j]]=1;
			if(i%Prime_List[j]==0)
				break;
		}
	}
}
int n,k;
map<int,int> Map;
int Answer;
inline map<int,int> Get_Prime_Sum(int n) {
	map<int,int> res;
	for(register int i=1; i<Prime_List_Length; ++i) {
		if(Prime_List[i]>n)
			break;
		while(n%Prime_List[i]==0)
			++res[Prime_List[i]],
			n/=Prime_List[i];
	}
	if(n!=1)
		res[n]=1;
	return res;
}
inline void Work() {
	cin>>n>>k;
	if(k==1) {
		cout<<"inf"<<endl;
		return;
	}
	Map.clear(),
	          Answer=2e18;
	Map=Get_Prime_Sum(k);
	int t,num,tmp,n_tmp;
	for(register map<int,int>::iterator it=Map.begin(); it!=Map.end(); ++it) {
		t=it->first,num=it->second,tmp=0,n_tmp=n;
		while(n_tmp>0)
			tmp+=n_tmp/t,
			     n_tmp/=t;
		tmp/=num;
		Answer=min(Answer,tmp);
	}
	cout<<Answer<<endl;
}
signed main() {
	Make_Prime_List();
	int t;
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0),cin>>t;
	int now=0;
	while(t--) {
		++now;
		printf("Case %d: ",now);
		Work();
	}
	return 0;
}

资料出处

  • [ 1 ] [1] [1]:CSDN;
  • [ 2 ] [2] [2]:OI-Wiki。
PhotovoltaicPanelCleanlinessDetector:基于YOLOv8的光伏板清洁状态监测系统 data.yamlyaml复制编辑names:0: clean1: dust3: leaves4: shadow✅ 高精度污染识别✅ 具备实时检测与UI展示✅ 可本地化部署应用未来方向增加污染程度分级(轻度、中度、严重)加入时间序列分析(污染变化趋势预测)无人机集成巡检模块。 阅读详情

相关推荐

第四节、C# 上位机面向对象编程详解(工控硬件继承实战版)

继承核心价值:在 C# 上位机工控开发中,继承的核心是通用逻辑复用与接口统一,将所有硬件的通用属性 / 方法封装到抽象基类,子类只需实现独有逻辑,大幅减少冗余代码。基类设计要点:优先使用抽象基类,合理分配访问修饰符(privateprotectedpublic),定义通用事件与虚方法,提供资源释放机制,兼顾复用性与扩展性。子类设计要点:通过: base()调用基类构造函数,强制实现抽象方法(保证接口统一),选择性重写虚方法(实现独有逻辑),复用基类的protected成员。多设备管理。

kylezhao2019的博客 794

HDU 3988 大数分解

题意:      这题把k素因子分解后看n!中有多少个与k对应的素因子。 n!中含有素因子p的个数为n/p+n/p^2.....取整。 #include #include #include #include using namespace std; typedef unsigned long long ll; const unsigned long long oo=92233720368

韩小侠的专栏 已迁移至lssea.com 971

Wi-Fi Sigma测试系统

Wi-Fi Sigma测试系统是Wi-Fi联盟(WFA)提出的一套全自动的WiFi认证测试系统,几乎涵盖的所有Wi-Fi的功能及性能(throughput)的自动化测试。该系统正逐步取代以前的WiFi认证测试系统。

Ke8323的博客 1万+

[数论] 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

蓝桥杯嵌入式(基础教程)STM32G431RBT6——创建工程以及点灯

首先选择正确的芯片类型:STM32G431RBT6工程的创建主要有配置时钟以及烧录的方式。在配置好之后需要对时钟进行配置,由于蓝桥杯的外部晶振是24MHz因此需要对时钟树进行相应的配置。第一步先点击时钟配置之后就可以对时钟进行相应的配置了最后一步,需要对工程起一个名字,并且要选择KEIL做为其相应的软件之后再需要再生成代码那里进行相应的控制。当然这样根据生成的工程不能直接使用会有一个报错,所以需要添加一个启动文件。这个启动文件可以在官方的LCD文件夹下复制到自己的工程中。

m0_74051113的博客 1093

LTspice基础教程-024.参数扫描;step指令用法

step指令用于参数扫描,扫描步骤可以是线性的,对数的或列表。 下面介绍几种常用用法: 绘制一简单电阻分压电路,如下: 线性扫描 语法:.step param <Name> <Start Value> <Stop Value> <Increment> 例:.step param Res 20 100 20 意思是R2的阻值从20变化到100,...

gaoyong_wang的博客 3万+

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

RunHarmony报错解析:如何解决data.use与cell.embeddings维度不匹配问题

本文深入解析了单细胞数据分析中RunHarmony函数报错'non-conformable arguments'的根源,即data.use与cell.embeddings矩阵维度不匹配。核心原因是assay(如RNA与integrated)错配导致细胞ID或数量不一致。文章提供了三种解决方案:最推荐显式指定assay.use参数,也可设置project.dim=FALSE或统一数据环境,并给出了最佳实践指南以避免此类错误。

weixin_29093017的博客 581

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

Dr_can Kalman Filter学习笔记(一)

本文是在b站Dr_can的卡尔曼滤波课程学习过程中的学习笔记

苏大侠的博客 1059

8.30华为OD机试真题 新系统 - 单词搜索计数 (Java/Py/C/C++/Js/Go)

8.30华为OD机试真题 新系统 - 单词搜索计数 (Java/Py/C/C++/Js/Go)

算法大师! 617

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 t

wust_cyl的博客 360

robosuite 入门教程(一)安装与基本用法

摘要:Robosuite是基于MuJoCo的模块化机器人仿真框架,提供标准化基准测试环境和多样化机器人控制功能。作为ARISE计划的一部分,该框架支持强化学习、模仿学习等算法研究,包含程序化环境生成、多模态传感器、多种控制器及遥操作设备。支持macOS/Linux系统,提供详细安装指南和功能演示脚本,包括随机动作测试、控制器验证、域随机化等。最新版本v1.5新增人形机器人支持、全身控制器和照片级渲染功能,旨在降低机器人学习研究门槛,促进算法开发与评估。

2506_90492529的博客 1275

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

HDU - 3988 Harry Potter and the Hide Story

题目: 1. 1 2. 1 3. 1 思路: 对k进行质因子分解,对于每一个质因子pi,k中出现的次数为cnt,计算出n!中包括该质因子的个数sum,那么对于pi的最大值就应该是sum/cnt。 当k=1时,答案是inf 代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include #

ACVevtor的博客 467

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 大素数分解+勒让德

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 (数论)

转载请注明出处,谢谢 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(数论-整数和素数)

题目大意: 给定n和k, 求 n! 能被 k^i 整除时,i 的最大取值。 解题思路: 将k分解质因素,问题变为,(1×2×3×...×n) 要被 ( p1^(i*a1) × p2^(i*a2) × ... × pn^(i*an) ) 整除,即分子中各分母的质因数的幂次要大于等于分母。 所以根据k的各质因素,求出满足各质因数的幂次 分子>=分母 的关系限制i,算出最大的i即可。 这题要用到unsigned long long,比较坑。。

wujy的专栏 963

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

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(分解素数)

题目链接: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

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

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
上一篇: 这一世,要学会二维凸包
下一篇: P2498 [SDOI2012] 拯救小云公主 并查集 二分
BestMonkey
博客等级 码龄3年 1312粉丝 74原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值