113 - Power of Cryptography

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
rickyok
New poster
Posts: 8
Joined: Mon Jun 10, 2002 5:17 pm
Location: Jakarta, Indonesia

113 - Power of Cryptography

Post by rickyok » Mon Jun 10, 2002 5:21 pm

Hi, I'm a newby here
Please help me on this case
I can easly make a function for search k for input :
2
16
3
27

But it goes to error when i got input like
7
4357186184021382204544

Any ideas how i can handle very2 large integer
(Without using float/ double) coz i've tried double
and have no used against very large int.

Thank you
PLease reply

ithamar
Learning poster
Posts: 56
Joined: Mon May 13, 2002 11:58 pm
Location: Venezuela

Post by ithamar » Mon Jun 10, 2002 10:08 pm

Implement your own routines to work with BigNumbers. Its not that hard :lol:. Strings is the answer ...

skylander
New poster
Posts: 13
Joined: Mon Jun 10, 2002 3:24 pm
Contact:

Post by skylander » Tue Jun 11, 2002 4:00 am

you do not need to use string arithmetic, just some formula and a double will do the job...

rickyok
New poster
Posts: 8
Joined: Mon Jun 10, 2002 5:17 pm
Location: Jakarta, Indonesia

Post by rickyok » Tue Jun 11, 2002 6:05 am

Well i've tried the string arithmathic but i failed
Becaused is not so simple to put a number into string and calculate a divide operation.

To Skylander:
Can you explain to me a little bit about that "Some formula and a double"

Thank you

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Tue Jun 11, 2002 9:21 am

This entire problem is just one math equation. If I tell you the equation, then there is NO problem:p But here's a hint, think about logarithms...

norton
New poster
Posts: 1
Joined: Tue Jul 02, 2002 5:30 pm
Location: Switzerland

problem 113 - complier error

Post by norton » Tue Jul 02, 2002 5:53 pm

Hi.
I have a problem with program no. 113. I posted it for many times but I always get compiler eror as the answer. I don't see what's wrong with the source code cause it works perfectly on my computer.
Here is the source code and the compiler's messages i received from the judge:

"@begin_of_source_code"

/* @JUDGE_ID: 10427NY 113 C */

#include <stdio.h>
#include <string.h>
#include <math.h>

long koren(char stev1[], char stev2[]);

int main(void)
{

char stev1[3];
char niz[102];
char stev2[102];
int i = 0;

while (scanf("%s", niz) == 1) {
i++;
if(i % 2 == 1) strcpy(stev1, niz);
else {
strcpy(stev2, niz);
printf("%ld\n", koren(stev1, stev2));
}
}
return 0;
}

long koren(char stev1[], char stev2[]) {

int j, mesta, eksp = 0;
long vsota = 0;
double osnova = 0;

for(j = 0; j < strlen(stev1) - 1; j++) {
eksp += (stev1[j] - '0') * pow(10, strlen(stev1) - 1 - j);
}
eksp += (stev1[j] - '0');

mesta = strlen(stev2) - 1;

if(mesta < 8) {
for(j = 0; j < mesta; j++) {
osnova += (stev2[j] - '0') * pow(10, mesta - j);
}
osnova += (stev2[j] - '0');
mesta = 0;
}

else {
for(j = 0; j < 8; j++) {
vsota += (stev2[j] - '0') * pow(10, 8 - j);
}
vsota += (stev2[j] - '0');
osnova = (double)vsota / pow(10, 8);
}
return (long)(pow(10, (log10(osnova) + mesta) / eksp) + 0.5);
}
"@end_of_source_code"



Here are the compiler error messages:

/usr/lib/crt1.o: In function `_start':
/usr/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

--
Can anyone help please?
Thanks.

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Tue Jul 02, 2002 6:02 pm

strange. the judge compiled it for me (but wrong answer). maybe your mailer screw it up? btw this is a linker error after compiling, for some reason the main() function was not found.

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

prob 113

Post by taj79 » Wed Jul 10, 2002 8:16 am

I want some hint...
i m unable to read the sample data(which one is really big....even with double )
Plz tell me what should I do?

visser
New poster
Posts: 8
Joined: Mon Jun 10, 2002 11:13 am
Location: Netherlands

Post by visser » Wed Jul 10, 2002 10:04 am

Do you really need that much precision to get the correct answer?

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Wed Jul 10, 2002 11:54 am

can u give me some tips how to attack the problem?if i can't read the number by scanf using a double variable how will i start?

Picard
Learning poster
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary
Contact:

Post by Picard » Wed Jul 10, 2002 1:22 pm

just read the older topics about P113
(this is what you should do first before creating a new topic...)

NONAME_SUST
New poster
Posts: 8
Joined: Tue Jul 23, 2002 9:15 am

HERE IS THE SOLUTION IN ALGORITHM WAY....(CODE IT)

Post by NONAME_SUST » Tue Jul 23, 2002 9:35 am

HELLO,
The problem has a very simple solution. After viewing the problem you may say How easy!!! You know that c++ has a library named <<math.h>> . We will use this library to solve the problem. Here it is:

long double s = pow (p,1/n);
printf("%lf",s);

And thats it.........
HEY WANT TO GET SOL.TRY ON http://www.uvexam.zzn.com from 1st September

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Wed Jul 24, 2002 1:05 pm

But my problem is reading p when it is big.

Code: Select all

#include<stdio.h>
#include<stdlib.h>

main()
{int d;
 long double p;
 scanf("%f",p);
 printf("%0.0f",p);
}
For the sample input I m failing to read the input.....[/code]

Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor » Wed Jul 24, 2002 2:01 pm

When you read double you must use %lf instead of %f. The latter will only read a float value. For long double I suppose you should use %Lf.
Not sure myself.

Ivor

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Wed Jul 24, 2002 3:03 pm

The problem is still there whether i use %lf or %Lf

I m unable to read the long sample input.

Post Reply

Return to “Volume 1 (100-199)”