程序是否计算2 ^ n + 1的素数,其中n是3位数? [英] Program to calculate the prime number or not for 2^n+1 where n is 3-digit number?

查看:113
本文介绍了程序是否计算2 ^ n + 1的素数,其中n是3位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序计算2 ^ n + 1是否为质数,其中n为3位数字?


我试图编写程序,但无法存储ex:2 ^ 123的较大值.

我声明了变量的时间,但是我无法存储这些值.

你能建议使用哪种数据类型来存储这么长的数字吗?


如果您有用于计算该程序的任何代码,请发送示例代码.

谢谢你
gowtham

Program to calculate the prime number or not for 2^n+1 where n is 3-digit number?


I tried to write the program but i am unable to store the large values for ex:2^123.

I declared the variable as long but i am unable to store the values.

Can u please suggest which datatype must use to store such a long number.


if u have any code for calculating this program please send the example code.

Thanking you
gowtham

推荐答案

C#中,long数据类型是一个带符号的整数,具有64位大小,那么它最多可以容纳2 ^ 63 -1.
如果使用unsigned long,则最多可以保留2 ^ 64-1的数字.

要保存大于这些的数字,应使用一些特定的类或库.您可以开始阅读本文: C#BigInteger类 [
In C# the long datatype is a signed integer with 64 bit size, then it could hold up to 2^63-1.
If you use unsigned long you will be able to hold numbers up to 2^64-1.

To hold numbers greater than these, you should use some specific class or library. You can start reading this article: C# BigInteger Class[^]


这篇关于程序是否计算2 ^ n + 1的素数,其中n是3位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆