zoukankan      html  css  js  c++  java
  • Power of Cryptography(数论)

    Description

    Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be only of theoretical interest.
    This problem involves the efficient computation of integer roots of numbers.
    Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is what your program must find).

    Input

    The input consists of a sequence of integer pairs n and p with each integer on a line by itself. For all such pairs 1<=n<= 200, 1<=p<10101 and there exists an integer k, 1<=k<=109 such that kn = p.

    Output

    For each integer pair n and p the value k should be printed, i.e., the number k such that k n =p.

    Sample Input

    2 16
    3 27
    7 4357186184021382204544

    Sample Output

    4
    3
    1234

    Source

    题目大意:

    已知公式 k^n =p, 输入 n 与 p 求解 k 的值并输出

    解题思路:

    k = p ^ (1/n), 注意数据范围即可

    #include <functional>
    #include <algorithm>
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <iomanip>
    #include <numeric>
    #include <cstring>
    #include <climits>
    #include <cassert>
    #include <complex>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <bitset>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <ctime>
    #include <list>
    #include <set>
    #include <map>
    
    //#include <tr1/unordered_set>
    //#include <tr1/unordered_map>
    //#include <array>
    
    using namespace std;
    
    #define REP(i, n) for (int i=0;i<n;++i)
    #define FOR(i, a, b) for (int i=a;i<b;++i)
    #define DWN(i, b, a) for (int i=b-1;i>=a;--i)
    #define REP_1(i, n) for (int i=1;i<=n;++i)
    #define FOR_1(i, a, b) for (int i=a;i<=b;++i)
    #define DWN_1(i, b, a) for (int i=b;i>=a;--i)
    #define REP_C(i, n) for (int n____=n,i=0;i<n____;++i)
    #define FOR_C(i, a, b) for (int b____=b,i=a;i<b____;++i)
    #define DWN_C(i, b, a) for (int a____=a,i=b-1;i>=a____;--i)
    #define REP_N(i, n) for (i=0;i<n;++i)
    #define FOR_N(i, a, b) for (i=a;i<b;++i)
    #define DWN_N(i, b, a) for (i=b-1;i>=a;--i)
    #define REP_1_C(i, n) for (int n____=n,i=1;i<=n____;++i)
    #define FOR_1_C(i, a, b) for (int b____=b,i=a;i<=b____;++i)
    #define DWN_1_C(i, b, a) for (int a____=a,i=b;i>=a____;--i)
    #define REP_1_N(i, n) for (i=1;i<=n;++i)
    #define FOR_1_N(i, a, b) for (i=a;i<=b;++i)
    #define DWN_1_N(i, b, a) for (i=b;i>=a;--i)
    #define REP_C_N(i, n) for (int n____=(i=0,n);i<n____;++i)
    #define FOR_C_N(i, a, b) for (int b____=(i=0,b);i<b____;++i)
    #define DWN_C_N(i, b, a) for (int a____=(i=b-1,a);i>=a____;--i)
    #define REP_1_C_N(i, n) for (int n____=(i=1,n);i<=n____;++i)
    #define FOR_1_C_N(i, a, b) for (int b____=(i=a,b);i<=b____;++i)
    #define DWN_1_C_N(i, b, a) for (int a____=(i=b,a);i>=a____;--i)
    
    #define ECH(it, A) for (__typeof((A).begin()) it=(A).begin(); it != (A).end(); ++it)
    #define rECH(it, A) for (__typeof((A).rbegin()) it=(A).rbegin(); it != (A).rend(); ++it)
    #define REP_S(i, str) for (char*i=str;*i;++i)
    #define REP_L(i, hd, suc) for (int i=hd;i;i=suc[i])
    #define REP_G(i, u) REP_L(i,hd[u],suc)
    #define REP_SS(x, s) for (int x=s;x;x=(x-1)&s)
    #define DO(n) for ( int ____n = n; ____n-->0; )
    #define REP_2(i, j, n, m) REP(i, n) REP(j, m)
    #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
    #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
    #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
    #define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
    #define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)
    
    #define ALL(A) A.begin(), A.end()
    #define LLA(A) A.rbegin(), A.rend()
    #define CPY(A, B) memcpy(A, B, sizeof(A))
    #define INS(A, P, B) A.insert(A.begin() + P, B)
    #define ERS(A, P) A.erase(A.begin() + P)
    #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin())
    #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin())
    #define CTN(T, x) (T.find(x) != T.end())
    #define SZ(A) int((A).size())
    #define PB push_back
    #define MP(A, B) make_pair(A, B)
    #define PTT pair<T, T>
    #define Ts *this
    #define rTs return Ts
    #define fi first
    #define se second
    #define re real()
    #define im imag()
    
    
    typedef long long LL;
    //typedef long double DB;
    typedef double DB;
    
    // k^n =p
    int main()
    {
        double n, p;
        while(cin >> n >> p){
            cout << pow(p, 1/n) << '
    ';
        }
    }
    
  • 相关阅读:
    es6实现简单模板编译
    JavaScript实现自定义短信模板
    关于JavaScript设计模式的学习(二)
    js获取可编辑区域光标位置
    关于JavaScript设计模式(一)
    为什么axios请求接口会发起两次请求
    axios基本用法
    webpack 配置文件
    IDEA系列(六)一This file is indented with tabs instead of 4 space
    IDEA系列(五)一控制台中文乱码
  • 原文地址:https://www.cnblogs.com/ygbrsf/p/12583008.html
Copyright © 2011-2022 走看看