go - 如何在 Golang 中将 Math.Pow 与整数一起使用
问题描述
我不断收到错误消息“不能在 math.Pow 的参数中使用 a(int 类型)作为 float64 类型,不能在 math.Pow 的参数中使用 x(int 类型)作为 float64 类型,无效操作:math.Pow(a, x ) % n (不匹配的类型 float64 和 int) "
func pPrime(n int) bool {
var nm1 int = n - 1
var x int = nm1/2
a := 1;
for a < n {
if (math.Pow(a, x)) % n == nm1 {
return true
}
}
return false
}
解决方案
func powInt(x, y int) int {
return int(math.Pow(float64(x), float64(y)))
}
如果您必须重复使用它并保持它更干净一点。
推荐阅读
- java - 如何从位图中获取 rgb 值?
- shell - 脚本中的 Sed 命令以查找字符串(如果存在),否则附加新字符串
- python - 用python翻译数据框列
- sas - 如何使用 proc mianalyze 预测测试集
- python - 根据列值在数据框中添加空白单元格(excel:插入单元格并右移)
- smalltalk - 我将如何使用 TableLayout 以不同的方式处理某些特定的子变形?
- javascript - 如何使用 Auth0 Lock 从响应对象中获取用户名?
- c# - 委托 BadStartNameChar 异常
- ios - 如果 URL 无法打开,则显示警报
- python - Lambda 函数不会从 MySQL 返回所有行