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

news2024/9/24 21:24:07

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 1T500
  2. 1 ≤ K ≤ 100000000000000 1 \leq K \leq 1 000 000 000 000 00 1K100000000000000
  3. 1 ≤ N ≤ 1000000000000000000 1 \leq N \leq 1 000 000 000 000 000 000 1N1000000000000000000

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 的最大取值。

解题思路

前置知识

  • 欧拉筛质数 [ 1 ] ^{[1]} [1]
  • 勒让德定理 [ 2 ] ^{[2]} [2]。(只要当结论记就行了,证明有兴趣自己去看吧)

正文

知道了勒让德定理,那就好办了。直接把 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。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1644817.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

黄历择日网php程序源码/日历老皇历万年历带免登录发布模块

黄历择日网php程序源码/日历老皇历万年历带免登录发布模块&#xff0c;不调用接口的&#xff0c;带数据库带黄历算法类&#xff0c;完整版免授权&#xff0c;完全开源程序&#xff0c;可二开&#xff01; 演示地址&#xff1a; https://s22.21sq.top/ 手机端地址&#xff1a…

等保建设技术建议书(Word原件)

1信息系统详细设计方案 1.1安全建设需求分析 1.1.1网络结构安全 1.1.2边界安全风险与需求分析 1.1.3运维风险需求分析 1.1.4关键服务器管理风险分析 1.1.5关键服务器用户操作管理风险分析 1.1.6数据库敏感数据运维风险分析 1.1.7“人机”运维操作行为风险综合分析 1.2…

Shiro-Action:基于Shiro的RESTful权限管理系统

摘要&#xff1a; 随着RESTful API的广泛应用&#xff0c;对权限管理的需求也日益增长。Shiro-Action是一个基于Shiro的权限管理系统&#xff0c;专注于RESTful风格的URL授权。本文将深入探讨Shiro-Action的设计思路、技术实现以及在实际项目中的应用价值。 一、引言 RESTful…

VGA项目:联合精简帧+双fifo+sobel算法 实现VGA显示

前言&#xff1a;该项目实际上是在很多基础的小练习上合成起来的&#xff0c;例如涉及到uart&#xff08;rs232&#xff09;的数据传输、双fifo流水线操作、VGA图像显示&#xff0c;本次内容在此基础上又增添了sobel算法&#xff0c;能实现图像的边沿监测并VGA显示。 文章目录…

算法学习007-进制转换 c++递归算法实现 中小学算法思维学习 信奥算法解析

目录 C进制转换 一、题目要求 1、编程实现 2、输入输出 二、算法分析 三、程序编写 四、程序说明 五、运行结果 六、考点分析 七、推荐资料 C进制转换 一、题目要求 1、编程实现 小明学c有一段时间了&#xff0c;今天他想做一个进制转换的小程序&#xff0c;将十进…

如何省下5000培训费学会月薪8000的嵌入式Linux?

嵌入式底层开发无疑是一项极为关键的技术&#xff0c;它在众多嵌入式系统中都有着广泛而重要的应用。在当今科技飞速发展的时代&#xff0c;嵌入式系统已经深入到我们生活的每一个角落&#xff0c;成为了我们日常生活中不可或缺的一部分&#xff0c;这也更加凸显了嵌入式开发的…

【Linux极简教程】常见实用命令不断更新中......

【Linux极简教程】常见实用命令不断更新中...... 常见问题1.Waiting for cache lock: Could not get lock /var/lib/dpkg/lock. It is held by process xxxx(dpkg) 常见问题 1.Waiting for cache lock: Could not get lock /var/lib/dpkg/lock. It is held by process xxxx(dp…

关于图形库

文章目录 1. 概念介绍2. 使用方法2.1 普通路由2.2 命名路由 3. 示例代码4. 内容总结 我们在上一章回中介绍了"使用get显示Dialog"相关的内容&#xff0c;本章回中将介绍使用get进行路由管理.闲话休提&#xff0c;让我们一起Talk Flutter吧。 1. 概念介绍 我们在本章…

stm32单片机开发五、使用I2C连接MPU6050

10轴就是3轴加速度、3轴角速度、3轴磁场强度和1个气压强度 任何一种传感器都不能获得精确且稳定的欧拉角&#xff0c;要想获得精确且稳定的欧拉角&#xff0c;就必须进行数据融合&#xff0c;把这几种传感器的数据结合起来&#xff0c;常见的数据融合算法&#xff0c;一般有互补…

可编程 IP 新星 Story Protocol 何以引领链上文艺复兴浪潮?

当前&#xff0c;随着 Web3 行业发展进入全新阶段&#xff0c;与生成式人工智能&#xff08;AIGC&#xff09;技术融合正在创造潜力新星项目。也是目前的互联网生态下&#xff0c;任何普通民众都有权利创作高质量的音乐、艺术、散文和视频内容&#xff0c;带来了用户生成内容&a…

Verilog中求两个数的差值

根据输入信号a,b的大小关系&#xff0c;求解两个数的差值&#xff1a;输入信号a,b为8bit位宽的无符号数。如果a>b&#xff0c;则输出a-b&#xff0c;如果a≤b&#xff0c;则输出b-a。 接口信号图如下&#xff1a; 代码如下&#xff1a; &#xff08;CSDN代码块不支持Veril…

去斯洛文尼亚旅游最有趣的徒步路线推荐

春天当然要去徒步呀&#xff01;斯洛文尼亚的徒步和登山小径纵横交错&#xff0c;遍布全国&#xff0c;尽管很多人首先想到的是高山地区连绵起伏的山峰&#xff0c;但实际上&#xff0c;在其他地区也有许多值得游览的徒步目的地。 ​ 这些低地地区的徒步路线将带你穿过如画的风…

【小行星数据预处理py-】

#数据的导入 import pandas as pd import numpy as np#导入EXCEL表格数据;na_values指定了将Excel文件中的空单元格转换为NaN df_excelpd.read_excel(C:/Users/galax/Desktop/MBA小行星数据/4000.xls,na_values0) #定义0为缺失值 see_datadf_excel #统计每一列的缺失值个数 pri…

可代替IRS2003的半桥栅极驱动器KP85211A 225V耐压 1A/1.5A

KP85211A是一款 225V 耐压&#xff0c;具有 1A 拉电流和 1.5A 灌电流能力的半桥栅极驱动器&#xff0c;专用于驱动功率MOSFET或IGBT。采用高压器件工艺技术&#xff0c;具有良好的电流输出及出色的抗瞬态干扰能力。可保证开关节点 VS 瞬态 -7V 情况下系统正常工作。可支持开关节…

Leetcode—706. 设计哈希映射【简单】(constexpr)

2024每日刷题&#xff08;127&#xff09; Leetcode—706. 设计哈希映射 数组实现代码 class MyHashMap { public:MyHashMap() {memset(arr, -1, sizeof(arr));}void put(int key, int value) {arr[key] value;}int get(int key) {if(arr[key] -1) {return -1;} return arr…

基于openEuler22.03 LTS环境的docker容器基础

一、说明 本文配置环境为VMware虚拟机或华为云服务器&#xff08;4核CPU&#xff0c;8 GB内存&#xff0c;40GB磁盘&#xff09;&#xff0c;OS为openEuler 22.03 LTS &#xff0c;Linux服务器要求能联网。 二、安装docker 2.1 安装docker软件包 [rootnode01 ~]# dnf -y in…

leetcode尊享面试——二叉树(python)

250.统计同值子树 使用dfs深度搜索&#xff0c;同值子树&#xff0c;要满足三个条件&#xff1a; 对于当前节点node&#xff0c;他的左子树血脉纯净&#xff08;为同值子树&#xff09;&#xff0c;右子树血脉纯净&#xff08;为同值子树&#xff09;&#xff0c;node的值等于…

第27章-配置PPP

1. 概述 2. 工作机制 3. 验证 4. PPP-MP 1. 概述 1.1 背景引入 以太网使用双绞线&#xff0c;广域网使用光纤&#xff1b; ① 定义&#xff1a;PPP协议即点到点协议&#xff1b; ② 应用场景&#xff1a;在串行线路上运行&#xff1b;主要是广域网 ③ 特点&#xff1a; 支持…

PHP 框架安全:ThinkPHP 序列 漏洞测试.

什么是 ThinkPHP 框架. ThinkPHP 是一个流行的国内 PHP 框架&#xff0c;它提供了一套完整的安全措施来帮助开发者构建安全可靠的 web 应用程序。ThinkPHP 本身不断更新和改进&#xff0c;以应对新的安全威胁和漏洞。 ThinkPHP 框架的安全特性&#xff1a; (1) 输入过滤和验证…

既能自动仿写公众号爆文,还能批量帮你上架闲鱼商品,打造自己的数字员工,简直yyds

「想象一下&#xff0c;如果有一个机器人在你的计算机上24小时不间断地工作&#xff0c;会不会做梦都笑着」 一、RPA机器人是什么&#xff1f; RPA——机器人流程自动化&#xff0c;它可以帮助人们完成重复性的、繁琐的工作&#xff0c;比如数据输入、网页爬取、自动化流程等…