Power of Cryptography(POJ 2109 math )

本文分享了解决POJ 2109题目的两种数学方法:利用exp和log函数,以及使用pow函数求解k和p之间的n值。通过实例演示了如何运用math.h库中的函数进行高效计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

~题目链接~

http://poj.org/problem?id=2109

输入

2 16
3 27
7 4357186184021382204544

结果

4
3
1234

kn = p,一直k和p,求n。

做完这道题,让我知道了math.h 的强大

1.exp+log

#include<cstdio>
#include<cstdlib>
#include<cmath>
int main()
{
    double n,m;
    while(~scanf("%lf%lf",&n,&m))
         printf("%.0f\n",exp(log(m)/n));//exp(计算指数,用来计算以e为底的x次方值,即ex值,然后将结果返回)
                                       //log(计算以e为底的对数值)
    return 0;
}

2.pow

#include<cstdio>
#include<cmath>
int main()
{
    double n,m;
    while(~scanf("%lf%lf",&n,&m))
        printf("%.0f\n",pow(m,1/n));//pow(用来计算以x为底的y次方值,即xy值,然后将结果返回)
    return 0;
}

 附带俩math的网址

http://hi.baidu.com/zsb517/item/ec2f99d2414e9514d90e4410
http://zh.wikipedia.org/zh/Math.h

转载于:https://www.cnblogs.com/guoyongzhi/p/3243138.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值