473,378 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Storing and doing modulus on long doubles

hello guys,

I'm implementing RSA algo in which i need to perform very huge integer power,mod functions. 'int' is having small range so i decided to go for long double. but,I am not able to use it.

can anybody plz tell me code to do following tasks:

take long double 26 & 53.

calculate 26^53 using pow fun.

calculate mod: (26^53)%250.

answer should be 76.

i'm not getting answer, Plz help.
May 8 '08 #1
7 4792
r035198x
13,262 8TB
hello guys,

I'm implementing RSA algo in which i need to perform very huge integer power,mod functions. 'int' is having small range so i decided to go for long double. but,I am not able to use it.

can anybody plz tell me code to do following tasks:

take long double 26 & 53.

calculate 26^53 using pow fun.

calculate mod: (26^53)%250.

answer should be 76.

i'm not getting answer, Plz help.
Please post what you have tried first.
May 8 '08 #2
long double a,b,c,d;
a=26;
b=53;

c=pow(a,b); //inbuilt pow fun.

//following 3 lines compute mod for long double.

d=c/250; //quotient
modfl(d,&d); //collectint integral part
c=c-(d*250); //get reminder i.e. mod(maths formula)

printf("%Lf",c) //c should be 76.
May 8 '08 #3
JosAH
11,448 Expert 8TB
For the modulo thing you don't need extremely large numbers; the remainders
(mod 250) for the first powers of 26 are 26, 176, 76, 226, 126; further powers
of 26 (mod 250) repeat this pattern; therefore 26^53 mod 250 == 26^3 mod 250 == 76.

kind regards,

Jos
May 8 '08 #4
friend,

i have given that example for understanding purpose to tell how i have done coding. those nos 26,53 & 250 are subject to change according to need.

what my question was how to use long double type because using that type, i'm not getting answers for large nos. such as
(26^53)mod 250.(answer should be 76).

i need code that calculates result for similar stuff. eg
(27^45)mod300 using long double.


thank u.
May 8 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
Hold on a minute.

d is c/250.

Therefore, d* 250 is c.

Therefore, c-(d*250) is really c - c which is 0.

What's the problem again?
May 8 '08 #6
guys,

d=c/250 is true but because it is long double so it gives qoutient(d) with fraction.

then i used 'modfl' function so that i get only integral part of d.

thus, c-(d*250) is not equal to zero. it gives mod.
because if c is divisible by 250 then it can be written as
c=qoutient*250+c mod 250
where,qoutient=c/250 & mod is what i want.

u guys are not helping out.

what my question is with values like 26 & 53. long double data type should give the answer of problem (26^53)mod250. but it gives 0.00000.

plz help me out. I have exam tomorrow.
May 9 '08 #7
JosAH
11,448 Expert 8TB
friend,

i have given that example for understanding purpose to tell how i have done coding. those nos 26,53 & 250 are subject to change according to need.

what my question was how to use long double type because using that type, i'm not getting answers for large nos. such as
(26^53)mod 250.(answer should be 76).

i need code that calculates result for similar stuff. eg
(27^45)mod300 using long double.


thank u.
You can't use long doubles for that; the result of 27^45 ==
25785133671514281396116148947909178321838248752307 264505595053707
which contains far too many digits for a long double.

Do the modulo trick I sketched instead:
Multiply 27 by itself modulo 300 until it starts to repeat itself:

27, 129, 183, 141, 207, 189, 3, 81, 87, 249, 123, 21, 267, 9, 243, 261, 147, 69, 63, 201, 27

The result (mod 300) of 27^21 is the same as 27^1 (mod 300) so the result of
27^45 (mod 300) is the same as 27^5 (mod 300) which is 207.

kind regards,

Jos
May 9 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dan | last post by:
Can someone tell me the difference between these three data types? Thanks Daniel
16
by: ferran | last post by:
How can I cast from (long double*) to (const double*) I have tried: const double* Value1 = (const double*)Value2; The compiler does not complain but the actual results when I access the...
2
by: Miguel Morales | last post by:
Hello: Currently, I am trying to solve a problem that requires the calculation of Airy functions for big arguments. Because Airy functions diverge rapidly for positive values, the results of the...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
5
by: Manikandan | last post by:
Hi, My application is processing a database(selecting data using execute reader) It takes much time. I want to show user the application is running, showing some information in the form I tried...
8
by: blaine | last post by:
Hey guys, For my Network Security class we are designing a project that will, among other things, implement a Diffie Hellman secret key exchange. The rest of the class is doing Java, while myself...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.