HDU 3641 Treasure Hunting

图机器学习(2)——图的可视化 图结构可通过图形化方式直观呈现。节点通常用圆形表示,边则用连接线表示。然而当节点和边数量增加时,绘制清晰的图形表示可能会变得相当困难,这主要源于节点在二维坐标系中的布局问题。对于包含数百个节点的图,手动指定每个节点的坐标显然不切实际。在本节中,我们将介绍如何在不指定每个节点坐标的情况下绘制图形。我们将利用两种不同的解决方案:networkx 和 Gephi。 阅读详情

Treasure Hunting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1321    Accepted Submission(s): 403


Problem Description
Zstu_yhr is a very curious person who fell in love with math when he was in elementary school phase. When he entered the middle school, he learned Multiplication and Power Multiplication. yhr is so ambitious that he not only dreams to be a mathematician but also dreams to be richer than Bill Gates.
One day, he is suddenly encountered with a crazy thought that is to hunt treasure to make one of his dreams a reality. Since yhr is such a strong-willed person that he will never give up as long as his goal has not been achieved. After going through 9*9 challenges, as a reward of god for that hard, he finally discovers an antique hole which is very likely to have a good number of treasures in it. However, as every novel writes, he can never get the treasures so easily. He has to open a coded door at first. He finds that there are 2*N numbers on the door. He speculates that they must be able to generate the password. Disappointedly, there isn’t any clue left for him. He has no better way but to YY. Firstly, he divides these 2*N number into N piles equally. The first pile is composed of a1,b1 and the second pile is composed of a2,b2...certainly, the i-th pile is composed of ai,bi…After completing this task, he calculates a1^b1*a2^b2*a3^b3…*an^bn and gets its result M. He takes M as the password to open the door. What’s a pity, he fails. Then he starts to YY again. Maybe the right password is the minimum number x which satisfies the equation x!%M=0. So he wants to have a try. But he doesn’t know how to get the number so that he has to turn to you for help. Can you help him?

 

Input
In the first line is an integer T (1<=T<=50) indicating the number of test cases.
Each test case begins with an integer n (1<=n<=100), then followed n lines. Each line contains two numbers ai and bi (1 <= ai <= 100, 1<=bi<=10000000000000)

 

Output
For each test case output the result x in one line. 
 

Sample Input
  
1 2 3 2 4 1
 

Sample Output
  
6
Hint
n! is the factorial of number n: 0!=1 n!=n*(n-1)! (n>=1) a^0=1 (a>=1) a^i=a*(a^i-1) (i>=1)
 

Source
 

质因子分解, x!中的质因子要恰好大于等于所有 a1^b1......ai^bi 中各个质因子的总和。

代码如下:

方法一(按位逼近):

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>

using namespace std;

struct point
{
    int ai;
    unsigned long long bi;
} a[102];
long long b[102];
int prime(int num)
{
    for(int i = 2; i <= (int)sqrt((double)num); i++)
        if(num % i == 0)
            return 0;
    return 1;
}
int main()
{
#ifdef test
    freopen("in.txt", "r", stdin);
#endif
    int t, n;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        scanf("%d", &n);
        memset(b, 0, sizeof(b));
        for(i = 0; i < n; i++)
            scanf("%d%I64u", &a[i].ai, &a[i].bi);
        for(i = 100; i >= 2; i--)
            if(prime(i))
                for(int j = 0; j < n; j++)
                    if(!(a[j].ai % i))
                    {
                        int k;
                        for(k = 1;; k++)
                            if(a[j].ai % (int)pow(i, k))
                                break;
                        b[i] += (k - 1) * a[j].bi;
                    }
        for(i = 100; i >= 2; i--)
            if(b[i])
                break;
        if(i < 2)
        {
            printf("0\n");
            continue;
        }
        long long max = -1, j, N, n_f;
        for(int k = i; k >= 2; k--)
            if(b[k])
            {
                int cov = (int)log10((double)b[k]) + 1;
                long long tem = pow(10.0, (double)cov), bb = 0;
                while(1)
                {
                    for(N = bb;; N += tem)
                    {
                        for(j = k,n_f = 0; j <= N; j *= k)
                            n_f += N / j;
                        if(b[k] <= n_f)
                            break;
                    }
                    if(!(tem / 10))
                        break;
                    bb = N - tem;
                    tem /= 10;
                }
                if(N > max)
                    max = N;
            }
        printf("%I64u\n",max);
    }
    return 0;
}

方法二(二分法):

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>

using namespace std;

struct point
{
    int ai;
    unsigned long long bi;
} a[102];
long long b[102];
int prime(int num)
{
    for(int i = 2; i <= (int)sqrt((double)num); i++)
        if(num % i == 0)
            return 0;
    return 1;
}
int main()
{
#ifdef test
    freopen("in.txt", "r", stdin);
#endif
    int t, n;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        scanf("%d", &n);
        memset(b, 0, sizeof(b));
        for(i = 0; i < n; i++)
            scanf("%d%I64u", &a[i].ai, &a[i].bi);
        for(i = 100; i >= 2; i--)
            if(prime(i))
                for(int j = 0; j < n; j++)
                    if(!(a[j].ai % i))
                    {
                        int k;
                        for(k = 1;; k++)
                            if(a[j].ai % (int)pow(i, k))
                                break;
                        b[i] += (k - 1) * a[j].bi;
                    }
        for(i = 100; i >= 2; i--)
            if(b[i])
                break;
        if(i < 2)
        {
            printf("0\n");
            continue;
        }
        long long max = -1, j, N, n_f;
        for(int k = i; k >= 2; k--)
            if(b[k])
            {
                long long l = 0, r = 0xfffffffffffffffLL;
                while(l < r)
                {
                    N = (l + r) >> 1;
                    for(j = k,n_f = 0; j <= N; j *= k)
                        n_f += N / j;
                    if(n_f >= b[k])
                        r = N;
                    else
                        l = N + 1;
                }
                if(l > max)
                    max = l;
            }
        printf("%I64u\n",max);
    }
    return 0;
}



102、栅极驱动芯片选型与设计 文章摘要 本文分享了栅极驱动芯片选型与设计的实战经验。通过一次因驱动芯片选型不当导致的炸管事故,作者总结了栅极驱动芯片选型的五个关键参数:峰值驱动电流、驱动电压范围、传播延迟匹配、欠压锁定和隔离等级。文章详细分析了自举电路设计中的常见陷阱,以及栅极电阻对开关特性的影响,并强调了PCB布局布线的重要性。最后,作者提供了七条实用建议,包括避免通用型驱动芯片、关注CMTI参数、使用插件电阻等。核心观点是:栅极驱动设计需要综合考虑参数匹配、电路布局和实际调试,示波器实测波形是验证设计的唯一标准。 阅读详情

相关推荐

加密视频如何破解 如何解除机器码绑定的视频

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 如何破解加密...

Q-980767270的博客 5万+

杭州邀请赛 Treasure Hunting

Treasure Hunting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 953    Accepte

codeStone 1204

国标GB28181视频平台EasyGBS国标平台设备播放断流现象的问题解决方案

于是排查代码发现,当设备网络较差时,设备会断流,超过指定的时间30s(EasyGBS平台默认值),就会主动清除流媒体服务,但是redis中的流数据还在,而当设备在录像时,自动保活会从redis中取保活流数据,所以就会出现设备状态显示正在播放,但是流已经消失的情况。有用户反馈,在安防视频监控EasyGBS运行时,接入的设备刚开始可以正常播放,开启云端录像后,也没有停止和重播的操作,但是出现了视频流断流的现象。在设备进行播放保活时,对流信息进行判断,添加一个最后的处理流时间,如果超过指定时间就自动重新拉流。

EasyNTS的博客 440

hdu 3641 - Treasure Hunting(筛素数+二分)

题意: 求最小的x!使得x!>= a1^b1*a2^b2*a3^b3.......; 思路: a总是在100以内的,所以分解质因数,保存其各个质因数的个数即可保存下来这个very big的大数; 然后二分x,求解最小的x即可。 代码如下: typedef long long LL; typedef unsigned long long LLU; const int M = 105;

稻草人 895

【华为鸿蒙3.0/荣耀安卓12使用VMOS Pro的激活方式 方法二】

关于荣耀手机安卓12如何解除进程限制,这里提供以下教程供小伙伴们参考。

Amy_mumu的博客 13万+

【Java】JAVA知识总结浅析

Java是一门功能强大的编程语言,广泛应用于多个领域。Java的编程思想,包括面向过程和面向对象编程,Java的发展历史,各版本的特点,JVM原理,数据类型,Java SE与Java EE的区别,应用场景,JDK与JDBC,Java Web技术,Spring Boot系列,以及MyBatis框架的基本实现,最后还将讨论Java在大数据、人工智能、嵌入式和Android等领域的应用。

wnm23的专栏 5320

Treasure Hunting HDU - 3468

题意:   输入一个n行m列的图   每次按字母顺序走最短路, 从一个字母走到下一个字母的过程中,只能拿走一个金子,求走完当前图中所有的字母后能拿到的金子的最大值 解析:   bfs求最短路   对于一个金子如果 dis1[i] + dis2[i] == dis1[next] 那么就代表着这个金子 在这条最短路上 可以拿 那么从上一个 字母 到当前节点连一条边 权值为1   ...

babing2770的博客 210

2026软件测试面试题全解析:从用例设计到接口自动化与性能实战

在软件测试岗位的招聘考察中,面试官越来越看重候选人解决实际问题的工程能力,而不仅仅是背诵概念。从最基础的测试用例设计出发,覆盖功能测试、接口测试、自动化测试、性能测试、数据库与Redis一致性等核心知识体系,是应对中高级岗位面试的关键路径。理解Postman抓包、Python脚本、Pytest框架、JMeter压测指标背后的原理,能帮助测试人员构建完整的质量保障思维。当AI辅助测试成为行业新趋势时,掌握数据校验链路与风险识别意识,更能体现资深测试工程师的竞争力。本文围绕2026年高频软件测试面试题,梳理了从

weixin_28676289的博客 253

HDU 3641 Treasure Hunting (二分+分解质因子)

HDU 3641 Treasure Hunting (二分+分解质因子)。神奇的二分。

n-1 1070

华为od机试|华为od机试真题2025|华为od题库|华为od机考|2025C卷B卷

华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|B卷C卷

u014481728的博客 10万+

Flutter SDK的删除与重装:一步步教你如何轻松搞定

在Flutter开发过程中,我们可能会遇到一些需要重新安装Flutter SDK的情况,例如升级Flutter版本、解决依赖冲突等。本文将详细介绍如何删除并重新安装Flutter SDK,让你轻松应对各种问题。

理论都是虚的,代码才是王道。 2250

hdu 3641 Treasure Hunting 强大的二分

1 /** 2 大意:给定一组ai,bi . m = a1^b1 *a2^b2 * a3^ b3 * a4^b4*...*ai^bi 3 求最小的x!%m =0 4 思路: 将ai 质因子分解,若是x!%m=0 那么x! 质因子分解之后 质因子的个数一定大于等于m的个数。二分求解可得 5 注意: 二分时,需要将,上下限 设定好,low =0; high = ...

a18865477815的博客 182

宇树 Qmini 双足机器人完全开源:3D打印+5小时组装,新手也能玩转!

教育教学,成为学校里的竞赛竞技,实验课程,论文设计的本体;开发者可以根据开源资料轻松集齐所有零部件,结构件可全部通过3D打印完成(几乎完全不需要任何机加工零部件),搭配宇树的高可靠性电机和标准电池,客户打印完零部件后,大概仅需要3~5小时的手工组装即可得到一只可爱的Qmini小双足机器人本体。一起推动机器人的未来发展,创新没有边界,创造力是无限的,Qmini就是你的第一步,如果你也想做一个能动、能学、还能萌的小双足机器人,现在就可以动手了,全开源、真低门槛、只差你的3D打印机和一点点耐心。

雕爷学编程 1895

解题报告:HDU3641Treasure Hunting 二分+勒让德定理

Treasure Hunting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2141    Accepted Submission(s): 653 Problem Description Zstu_yhr is a

Hee的博客~ 585

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

VB摄像头监控

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

HDU 3641 Treasure Hunting (素数拆分)

题意:有N个ai,bi,M=a1^b1*a2^b2*a3^b3…*an^bn ,求最小的 x 使得 x! % M ==0. 思路:把M分成多个素数相乘,num[i] 记录素数 i 的个数,然后二分找到x,若 x! 中所有 i 的个数满足>=num[i] 即为答案。 #include #include #include #include #include #include #i

不吸血的Vampire 815

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

hdu3641 Treasure Hunting(灵活题,阶乘的素因子个数求法)

http://acm.hdu.edu.cn/showproblem.php?pid=3641 题意:有N个ai(aia1^b1*a2^b2*a3^b3…*an^bn ,求最小的 x 使得 x! % M ==0. 思路:先把M的每个素因子的个数求出来,再二分x,判断M的每个素因子是不是在mid!里个数都比M多,是的话就符合了。 知识点:对于n的阶乘中含有的某个质因子x的个数ans求法:

芒果街上的小屋(此博客暂时停用) 940

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

HDU 3641 Treasure Hunting(阶乘素因子分解+二分)

Description Zstu_yhr is a very curious person who fell in love with math when he was in elementary school phase. When he entered the middle school, he learned Multiplication and Power Multiplication....

she 433
上一篇: UVa 10706 - Number Sequence(POJ 1019)
下一篇: HDU 3650 Hot Expo
GooMaple
博客等级 码龄14年 79粉丝 197原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值