113 - Power of Cryptography
Moderator: Board moderators
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
Maybe my math skills are a little rusty, but I thought the formula wasTry the formula:
a log b = log b / log a
a log b = log (b^a)
![:wink:](./images/smilies/icon_wink.gif)
and for the compiler warnings (Visual C++ doesn't have any problem with that,) the problem statement guarantees k to be less than 1E9. i used double for the precision in the log statement, and then since it is guaranteed by problem statement to fit in long, i did the basic round-and-convert. i also tried submitting the answer as a double with the ios::showpoint flag off, but no dice.
thanks for the replies...although i haven't had any problems previously either copy and pasting or uploading the code from visual, could that be a problem?
thanks again
"Moral victories are for girls!" -- Shawn Kiernan
"You can't spell geek without EE..." -- Larkin Gentry
"You can't spell geek without EE..." -- Larkin Gentry
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
To bignad:
Yes, a log b equals log(b^a). That's why I added some note since I don't know how to type 'a' in superscript model. The 'a' in 'a log b' here doesn't mean a * log b, get it??
I recommend this formula since it's more precise.
Yes, a log b equals log(b^a). That's why I added some note since I don't know how to type 'a' in superscript model. The 'a' in 'a log b' here doesn't mean a * log b, get it??
![:wink:](./images/smilies/icon_wink.gif)
![:wink:](./images/smilies/icon_wink.gif)
I recommend this formula since it's more precise.
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.
Ok I'm sorry but I'm still having some problems understanding that formula. i think i understand it now to mean
a log(a) b = log(a) b / log(a) a
where the a in parenthesis means log(base a) of.
e ln b = ln b / ln e --> e ln b = ln b
can you tell me where i'm going wrong? and even after that, i'm unclear on how to express p=k^n in the form ln b / ln a:
ln p = ln k^n --> ln p = n ln k --> 1/n = ln k / ln p -->(by blind app of formula) --> 1/n = p ln k
sorry, i have been out of school for a while..![:(](./images/smilies/icon_frown.gif)
a log(a) b = log(a) b / log(a) a
where the a in parenthesis means log(base a) of.
so using natural logs, it seems that the formula would bePS: a in a log b is the base of the log
e ln b = ln b / ln e --> e ln b = ln b
can you tell me where i'm going wrong? and even after that, i'm unclear on how to express p=k^n in the form ln b / ln a:
ln p = ln k^n --> ln p = n ln k --> 1/n = ln k / ln p -->(by blind app of formula) --> 1/n = p ln k
sorry, i have been out of school for a while..
![:(](./images/smilies/icon_frown.gif)
"Moral victories are for girls!" -- Shawn Kiernan
"You can't spell geek without EE..." -- Larkin Gentry
"You can't spell geek without EE..." -- Larkin Gentry
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
-
- New poster
- Posts: 43
- Joined: Mon Oct 13, 2003 4:54 pm
- Location: Mexico
- Contact:
113 - Why Wrong Answer? :'(
113 - Why Wrong Answer?
This is my code.
k = 10^(log10(p)/n);
[c]
/*
Power Criptography
problem: 113
*/
# include <stdio.h>
# include <math.h>
# include <string.h>
main(){
int n,val,c,i;
double x;
int k;
char p[200];
while(scanf("%d\n",&k) != EOF){
gets(p);
n = strlen(p);
c = 100;
val = 0;
for(i = 0; i<4;i++ , c /=10){
if(p == NULL) break;
val += (p-'0')*c;
}
x = log10((double)val);
x = x-3+n;
x /= k;
printf("%.0lf\n",pow(10,x));
}
return 0;
}[/c]
![:cry:](./images/smilies/icon_cry.gif)
This is my code.
k = 10^(log10(p)/n);
[c]
/*
Power Criptography
problem: 113
*/
# include <stdio.h>
# include <math.h>
# include <string.h>
main(){
int n,val,c,i;
double x;
int k;
char p[200];
while(scanf("%d\n",&k) != EOF){
gets(p);
n = strlen(p);
c = 100;
val = 0;
for(i = 0; i<4;i++ , c /=10){
if(p == NULL) break;
val += (p-'0')*c;
}
x = log10((double)val);
x = x-3+n;
x /= k;
printf("%.0lf\n",pow(10,x));
}
return 0;
}[/c]
Power of Cryptography (#113)
I have a problem:
It seems to be OK but I got WA??? I can't find error!
Can somebody help me?
{@BEGIN_OF_SOURCE_CODE}
{ @JUDGE_ID: XXX 113 Pascal}
program proga;
var datan,datap:string;
procedure nsqrt(ns,ps:string);
var n,p,ost,res:integer;
code,v:integer;
begin
val(ns,n,code);
v:=(length(ps) div n)+1;
ost:=length(ps)-v;
if ost>0 then
begin
val(copy(ps,1,v),p,code);
res:=round(exp(1/n*(ln(p)+ost*ln(10))));
end else
begin
val(ps,p,code);
res:=round(exp(1/n*(ln(p))));
end;
writeln(res);
end;
begin
while not eof(input) do
begin
readln(datan);
readln(datap);
nsqrt(datan,datap);
end;
end.
{@END_OF_SOURCE_CODE}
It seems to be OK but I got WA??? I can't find error!
Can somebody help me?
{@BEGIN_OF_SOURCE_CODE}
{ @JUDGE_ID: XXX 113 Pascal}
program proga;
var datan,datap:string;
procedure nsqrt(ns,ps:string);
var n,p,ost,res:integer;
code,v:integer;
begin
val(ns,n,code);
v:=(length(ps) div n)+1;
ost:=length(ps)-v;
if ost>0 then
begin
val(copy(ps,1,v),p,code);
res:=round(exp(1/n*(ln(p)+ost*ln(10))));
end else
begin
val(ps,p,code);
res:=round(exp(1/n*(ln(p))));
end;
writeln(res);
end;
begin
while not eof(input) do
begin
readln(datan);
readln(datap);
nsqrt(datan,datap);
end;
end.
{@END_OF_SOURCE_CODE}
#113 why compile error???pliz help
[c]
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main(void)
{
long n,p,loop;
while(scanf("%ld\n%ld",&n,&p)==2)
{
for(loop=1;loop<=p;loop++)
{
if((long)(pow(n,loop))==p)
{
printf("%ld\n",loop);
break;
}
}
}
}[/c]
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main(void)
{
long n,p,loop;
while(scanf("%ld\n%ld",&n,&p)==2)
{
for(loop=1;loop<=p;loop++)
{
if((long)(pow(n,loop))==p)
{
printf("%ld\n",loop);
break;
}
}
}
}[/c]
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius