## 113 - Power of Cryptography

Moderator: Board moderators

Salehwar
New poster
Posts: 9
Joined: Mon Oct 09, 2006 3:48 pm
Try this out.. it worked with me:

Code: Select all

``cout<<setiosflags(ios::fixed)<<setprecision(0)<<pow(p, 1.0/n)<<endl;``
Also this way works too:

Code: Select all

``k = pow(p, 1.0/n); printf("%.0lf\n",k); ``

With both ways n, p, k are defined as double. Let know if it worked with you.

Edit: Edited the codes.. forgot something to mention.

Saul Hidalgo
New poster
Posts: 18
Joined: Wed Jan 03, 2007 2:36 am
Location: Los Teques, Venezuela

### 113 Somebody can Help me? WA

I did send the exercise 113 and i dont know why.
Here is the code...

Code: Select all

``````#include <iostream>
#include <cmath>

using namespace std;

int main(){
double k,p,temp;
while(cin>>k>>p){
temp=(1.0)/k;
cout << floor(pow(p,temp))<<endl;
}
return 0;
}``````
And i too submit is code, but i had been WA.

Code: Select all

``````#include <iostream>
#include <cmath>

using namespace std;

int main(){
double k,p,temp;
while(cin>>k>>p){
temp=(1.0)/k;
cout << pow(p,temp)<<endl;
}
return 0;
}``````
Thanks.

rickyliu
New poster
Posts: 30
Joined: Thu Sep 28, 2006 7:16 am
Your program cannot solve the last case of the sample input. Consider using log.

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Contact:
Try again using

Code: Select all

``````	cout.setf(ios::fixed);
cout.precision(0); ``````
at very beginning of main function

sathyashrayan
New poster
Posts: 6
Joined: Tue Apr 25, 2006 6:48 pm

### 113, WA (beginner)

Dear group,
My code is wrong, I know that very well. The code just simply hangs.. Can any one help.. Thnaks..

Code: Select all

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

int main(void)
{
long long k,
n,
result,
p;

unsigned int       i;

i = pow(10,101);

/*Give p and n we need to find k, which is the n pow k */

scanf("%lld %lld",&n,&p);
for(k =1 ; k < pow(10,9); k ++)
{
result = pow(n,k);
if(result == p)
{
printf("%lld\n",k);

}

if(p > i)
exit(0);
}

return 0;
}
``````

vijay03
New poster
Posts: 33
Joined: Wed Sep 13, 2006 6:46 pm
Contact:
Since the nos are very large here, it is sufficient to take the root and store it in a long double. Just do the following:

1. You need to keep taking input as long as the judge keeps giving them. For that, use

Code: Select all

``````
while(scanf("%lf %lf",&n,&p)==2)
{

// the processing of each pair of input
}

``````
2. Inside the while loop, simply calculate p to the power 1.0/n, floor the result and print with "%0.lf\n"

Hope this helps

Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:
I thing double is enough to solve this problem
Akash chhoyar swopno
Dream to touch the sky

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### 113:

Code: Select all

``````
Thanks stubbscroll
GOT AC.

``````
Last edited by lnr on Thu Jul 05, 2007 6:57 pm, edited 2 times in total.

stubbscroll
Experienced poster
Posts: 151
Joined: Tue Nov 16, 2004 7:23 pm
Location: Norway
Contact:
Change long double to double and don't forget to remove your code if it works.

smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am
god! this is a frightening bad problem! i remember that i was very frustrated with this one!
fahim
#include <smile.h>

Saul Hidalgo
New poster
Posts: 18
Joined: Wed Jan 03, 2007 2:36 am
Location: Los Teques, Venezuela
Good. Thanks. I got AC

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

### Re: 113- power of cryptography T\E

I have got acc before. But now I get T/E. Why

Code: Select all

``````Removed After A/C
``````
Last edited by noor_aub on Sun Aug 15, 2010 7:37 pm, edited 3 times in total.

fahim_xubayer
New poster
Posts: 5
Joined: Wed Sep 23, 2009 8:57 am

### Re: 113- power of cryptography - What is the algorithm?

@ noor vai

have a look at the way you are taking the input it should be while(scanf("%lf %lf",&b,&a)==2)
hope this kids advice helps LOL

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

### Re: 113- power of cryptography - What is the algorithm?

Thanks

New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

Code: Select all

``````#include<math.h>
#include<iostream>
using namespace std;
int main()
{
long double f,s,t;
//freopen("in.txt","r",stdin);
while(scanf("%lf%lf",&f,&s)==2)
{
t=exp(log(s)/f);
printf("%.0lf\n",t);
}
return 0;
}
``````