Exemplo n.º 1
0
int main()
{
    int a, b, k, n, m;
    scanf("%d%d%d%d%d", &a, &b, &k, &n, &m);
    C[0] = 1;
    for (int i = 0; i < k; i++)
        for (int j = i + 1; j; j--)
            C[j] = (C[j] + C[j - 1]) % mod;
    printf("%d", (int64(C[n]) * fast_pow(a, n) * fast_pow(b, m)) % mod);
    return 0;
}
Exemplo n.º 2
0
int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
	int  t,n,i;
	long long int k;
	
	/*int ans[100]={4, 6, 10, 18, 34, 66, 130, 258, 514, 1026, 2050, 4098, 8194, 16386, 32770, 65538, 131074,
	 262146, 524290 ,1048578, 2097154 ,4194306 ,8388610, 16777218 ,33554434 ,67108866 ,134217730, 268435458,
	 536870914, 73741819, 147483636 ,294967270 ,589934538, 179869067 ,359738132, 719476262, 438952515, 877905028 ,
	 755810047, 511620085, 23240161, 46480320 ,92960638, 185921274 ,371842546, 743685090 ,487370171 ,974740340, 949480671,
	  898961333, 797922657 ,595845305, 191690601 ,383381200, 766762398, 533524787, 67049565 ,134099128, 268198254, 536396506, 72793003 ,
	  145586004 ,291172006, 582344010, 164688011 ,329376020 ,658752038, 317504067 ,635008132 ,270016255 ,540032508 ,80065007, 160130012 ,320260022,
	   640520042, 281040075 ,562080148, 124160287 ,248320572 ,496641142 ,993282282 ,986564555, 973129101, 946258193 ,892516377 ,785032745 ,570065481,
	    140130953, 280261904, 560523806 ,121047603 ,242095204, 484190406 ,968380810 ,936761611 ,873523213, 747046417 ,494092825 ,988185648 ,976371287};
	
	*/
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		
		scanf("%d",&n);
		//k=pow(2,n+1)+2;
		//k=k%1000000007;
		printf("%lld\n",fast_pow(2,n+1)+2);
		
		
	}



    return 0;
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {
	freopen("math.in", "r", stdin);
	freopen("math.out", "w+", stdout);
	ll x, y;
	scanf("%lli %lli", &x, &y);
	printf("%lli", fast_pow(x, y));
	return 0;
}
Exemplo n.º 4
0
double fast_pow(double x, int n) {
    if (n == 0)
        return 1;
    double y = fast_pow(x, n/2);
    if (n%2 == 0)
        return y*y;
    else 
        return y*y*x;
}
Exemplo n.º 5
0
int main()
{
    int a,n;
    scanf(" %d %d",&a,&n);
    printf(" %f",pow(a,n));
    printf(" %d %d\n",n<<1,n>>1);
    //for(n=1;n<21;n++)
    //printf("%lld\n",iter_pow(2,n));
    printf(" %lld",fast_pow(a,n));
    return 0;
}
Exemplo n.º 6
0
int main()
{
    int t, x;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &x);
        printf("%d\n", 4 * x % mod * fast_pow(5, x - 1) % mod);
    }
    return 0;
}
ull fastpow(ull a,ull b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ull temp=fast_pow(a,b/2);
	if(b%2)
		return((((temp*temp)%MOD)*a)%MOD);
	else
		return (temp*temp)%MOD;
}
Exemplo n.º 8
0
int main()
{
    int m,x,k;
    freopen("circle.in","r",stdin);
    freopen("circle.out","w",stdout);
    scanf("%d%d%d%d",&n,&m,&k,&x);
    long long tmp=(long long)fast_pow(10,k);
    tmp*=m;
    tmp%=n;
    tmp+=x;
    tmp%=n;
    printf("%lld",tmp);
    return 0;
}
Exemplo n.º 9
0
int main() {
    int ____localvar____11;
    int ____localvar____12;
    int ____localvar____13 = 9;
    while (____localvar____13 != 0)
        switch (int ____localvar____13 = 9) {
          case 1:
            {
              ____label____15:
                ;
                break;
            }
          case 2:
            {
              ____label____14:
                ;
                ____localvar____13 = 8;
                break;
            }
          case 3:
            {
              ____label____11:
                ;
                ____localvar____13 = 2;
                break;
            }
          case 4:
            {
              ____label____12:
                ;
                std::cout << fast_pow(2, 17) << std::endl;
                return 0;
                break;
            }
          case 5:
            {
                ____localvar____13 = 3;
                break;
            }
          case 6:
            {
                ____localvar____13 = 4;
                break;
            }
          case 7:
            {
              ____label____10:
                ;
                ____localvar____12 = 1;
                if (____localvar____12 == 1) {
                    ____localvar____13 = 6;
                } else {
                    ____localvar____13 = 5;
                }
                ____localvar____13 = 6;
                break;
            }
          case 8:
            {
              ____label____13:
                ;
                if (____localvar____11 != 0) {
                    ____localvar____13 = 7;
                } else {
                    ____localvar____13 = 1;
                }
                ____localvar____13 = 7;
                break;
            }
          case 9:
            {
                ____localvar____11 = 1;
                ____localvar____13 = 8;
                break;
            }
        }
}
Exemplo n.º 10
0
double fast_pow(double ____localvar____5, int ____localvar____6) {
    double ____localvar____7;
    int ____localvar____8;
    int ____localvar____9;
    int ____localvar____10 = 27;
    while (____localvar____10 != 0)
        switch (int ____localvar____10 = 27) {
          case 1:
            {
              ____label____9:
                ;
                break;
            }
          case 2:
            {
              ____label____8:
                ;
                ____localvar____10 = 26;
                break;
            }
          case 3:
            {
              ____label____1:
                ;
                ____localvar____10 = 2;
                break;
            }
          case 4:
            {
                ____localvar____10 = 3;
                break;
            }
          case 5:
            {
                ____localvar____8 = 3;
                ____localvar____10 = 4;
                break;
            }
          case 6:
            {
                ____localvar____8 = 4;
                ____localvar____10 = 4;
                break;
            }
          case 7:
            {
              ____label____2:
                ;
                if (____localvar____6 == 0) {
                    ____localvar____10 = 6;
                } else {
                    ____localvar____10 = 5;
                }
                ____localvar____10 = 6;
                break;
            }
          case 8:
            {
              ____label____3:
                ;
                return 1;
                break;
            }
          case 9:
            {
                ____localvar____10 = 3;
                break;
            }
          case 10:
            {
                ____localvar____8 = 1;
                ____localvar____10 = 9;
                break;
            }
          case 11:
            {
                ____localvar____8 = 2;
                ____localvar____10 = 9;
                break;
            }
          case 12:
            {
              ____label____4:
                ;
                ____localvar____7 = fast_pow(____localvar____5, ____localvar____6 / 2);
                if (____localvar____6 % 2 == 0) {
                    ____localvar____10 = 11;
                } else {
                    ____localvar____10 = 10;
                }
                ____localvar____10 = 11;
                break;
            }
          case 13:
            {
              ____label____5:
                ;
                return ____localvar____7 * ____localvar____7;
                break;
            }
          case 14:
            {
              ____label____6:
                ;
                return ____localvar____7 * ____localvar____7 * ____localvar____5;
                break;
            }
          case 15:
            {
                ____localvar____10 = 3;
                break;
            }
          case 16:
            {
                ____localvar____10 = 14;
                break;
            }
          case 17:
            {
                if (____localvar____9 == 1) {
                    ____localvar____10 = 16;
                } else {
                    ____localvar____10 = 15;
                }
                ____localvar____10 = 16;
                break;
            }
          case 18:
            {
                ____localvar____10 = 13;
                break;
            }
          case 19:
            {
                if (____localvar____9 == 2) {
                    ____localvar____10 = 18;
                } else {
                    ____localvar____10 = 17;
                }
                ____localvar____10 = 18;
                break;
            }
          case 20:
            {
                ____localvar____10 = 12;
                break;
            }
          case 21:
            {
                if (____localvar____9 == 3) {
                    ____localvar____10 = 20;
                } else {
                    ____localvar____10 = 19;
                }
                ____localvar____10 = 20;
                break;
            }
          case 22:
            {
                ____localvar____10 = 8;
                break;
            }
          case 23:
            {
                if (____localvar____9 == 4) {
                    ____localvar____10 = 22;
                } else {
                    ____localvar____10 = 21;
                }
                ____localvar____10 = 22;
                break;
            }
          case 24:
            {
                ____localvar____10 = 7;
                break;
            }
          case 25:
            {
              ____label____0:
                ;
                ____localvar____9 = (____localvar____8);
                if (____localvar____9 == 5) {
                    ____localvar____10 = 24;
                } else {
                    ____localvar____10 = 23;
                }
                ____localvar____10 = 24;
                break;
            }
          case 26:
            {
              ____label____7:
                ;
                if (____localvar____8 != 0) {
                    ____localvar____10 = 25;
                } else {
                    ____localvar____10 = 1;
                }
                ____localvar____10 = 25;
                break;
            }
          case 27:
            {
                ____localvar____8 = 5;
                ____localvar____10 = 26;
                break;
            }
        }
}
Exemplo n.º 11
0
//if m is prime, ETF of m is m - 1
//Generally, formula is fast_pow(a, ETF(m) - 1)
//For this to be valid, gcd(a,m) should be 1 i.e they should be co-prime to each other.
lli modInverse(lli a, lli m) {
    return fast_pow(a, m - 2);
}
Exemplo n.º 12
0
int main() {
    fast_pow(2.5, 50);
    return 0;
}
Exemplo n.º 13
0
 static float fast_pow (float base, int exponent) {
     if (exponent == 0) return 1.0;
     if (exponent == 1) return base;
     if (exponent % 2 == 0) {float t = fast_pow (base, exponent / 2); return t * t;}
     else return fast_pow (base, exponent - 1) * base;
 }
Exemplo n.º 14
0
    static vl::ErrorCode
    backward(type * output,
             type const* data,
             type const* derOutput,
             size_t width,
             size_t height,
             size_t depth,
             size_t num,
             size_t normDepth,
             type kappa, type alpha, type beta)
    {
      int m1 = ((signed)normDepth-1)/2 ;
      int m2 = (int)normDepth - m1 - 1 ;
      int offset = (int)width*(int)height ;
      type ab2 = 2*alpha*beta ;
      int t, q ;

#ifndef VL_NNNORMALIZE_FAST
      for (int k = 0 ; k < num ; ++k) {
        for (int h = 0 ; h < height ; ++h) {
          for (int w = 0 ; w < width ; ++w) {
            type const* x = data + w + h * width ;
            T* y = output + w + h * width ;
            type const* z = derOutput + w + h * width ;
            type acc = 0 ;
            for (t = 0 ; t < (signed)depth ; ++t) {
              yat(t) = 0 ;
            }
            for (t = -m2 ; t < (signed)depth ; ++t) {
              int q1 = t-m1 ;
              int q2 = t+m2 ;
              type ap = 0 ;
              type am = 0 ;
              if (t-m1-1 >= 0) { am = xat(t-m1-1) ; } else { q1 = 0 ; }
              if (t+m2 < depth) { ap = xat(t+m2) ; } else { q2 = depth - 1 ; }
              acc += ap*ap - am*am ;
              type L = kappa + alpha * acc ;
              type Lbeta = fast_pow(L, -beta) ;
              type Lbeta1 = Lbeta / L ;

              if (0 <= t && t < depth) {
                yat(t) += zat(t) * Lbeta ;
                for (q = q1 ; q <= q2 ; ++ q) {
                  yat(q) -= zat(t) * xat(t) * xat(q) * ab2 * Lbeta1 ;
                }
              }
            }
          }
        }
        data += width*height*depth ;
        output += width*height*depth ;
        derOutput += width*height*depth ;
      }
#else
      type * restrict acc = (type*) malloc(sizeof(type) * width*height) ;
      type * restrict acc2 = (type*) malloc(sizeof(type) * width*height*depth) ;
      for (int k = 0 ; k < num ; ++k) {
        memset(acc, 0, sizeof(type) * width*height) ;
        for (t = -m2 ; t < (signed)depth ; ++t) {
          /*
           Compue the square of the input data x.^2 summed in the normalization window. This is done
           incrementally, by updating the previous normalization window sum.
           */
          {
            int const tm = t - m1 - 1 ;
            int const tp = t + m2 ;
            type const* restrict datam_ = data + offset * tm ;
            type const* restrict datap_ = data + offset * tp ;
            type *end = acc + width*height ;

            if (0 <= tm && tp < depth) {
              for(type * restrict acc_ = acc ; acc_ != end ; ++acc_, ++datap_, ++datam_) {
                type am = *datam_ ;
                type ap = *datap_ ;
                *acc_ += ap*ap - am*am ;
              }
            } else if (0 > tm && tp < depth) {
              for(type * restrict acc_ = acc ; acc_ != end ; ++acc_, ++datap_) {
                type ap = *datap_ ;
                *acc_ += ap*ap ;
              }
            } else if (0 <= tm && tp >= depth) {
              for(type * restrict acc_ = acc ; acc_ != end ; ++acc_, ++datam_) {
                type am = *datam_ ;
                *acc_ -= am*am ;
              }
            }
          }

          /*
           Compute the arguments of the summation in the derivative
           expression, storing them into acc2.
           */
          if (0 <= t && t < depth) {
            type const* restrict data_ = data + offset * t ;
            type const* restrict derOutput_ = derOutput + offset * t ;
            type * restrict output_ = output + offset * t ;
            type * restrict acc2_ = acc2 + offset * t ;
            type * end = acc + width*height ;
            for(type * restrict acc_ = acc ; acc_ != end ;
                ++acc_, ++acc2_, ++data_, ++derOutput_, ++output_) {
              type L = kappa + alpha * (*acc_) ;
              type Lbeta = fast_pow(L, -beta) ;
              type temp1 = (*derOutput_) * Lbeta ;
              type temp2 = (*data_) * ab2 * temp1 / L ;
              *output_ = temp1 ;
              *acc2_ = temp2 ;
            }
          }
        }

        /*
         Integrate along feature channels in acc2, summing plane t-1 to
         plane t.
         */
        for (t = 1 ; t < (signed)depth ; ++t) {
          type * restrict acc2_ = acc2 + t * offset ;
          type const* restrict src_ = acc2_ - offset ;
          type const* end = acc2_ + offset ;
          for( ; acc2_ != end ; ++acc2_, ++src_) {
            *acc2_ += *src_ ;
          }
        }

        /*
         Compute summation in the derivative expression from the integral
         just obtained.
         */
        for (t = 0 ; t < (signed)depth ; ++t) {
          int q1 = t - m2 - 1 ;
          int q2 = ((t + m1) <= (depth - 1)) ? t + m1 : depth - 1 ;
          type const* restrict acc22_ = acc2 + offset * q2 ;
          type const* restrict acc21_ = acc2 + offset * q1 ;
          type const* restrict data_  = data + offset * t ;
          type const* restrict end = data_  + width*height ;
          type * restrict output_ = output + offset * t ;
          if (q1 >= 0) {
            for( ; data_ != end ; ++data_, ++acc22_, ++acc21_, ++output_) {
              *output_ -= (*acc22_ - *acc21_) * (*data_) ;
            }
          } else {
            for( ; data_ != end ; ++data_, ++acc22_, ++output_) {
              *output_ -= (*acc22_) * (*data_) ;
            }
          }
        }
        data += width*height*depth ;
        output += width*height*depth ;
        derOutput += width*height*depth ;
      }
Exemplo n.º 15
0
    static vl::ErrorCode
    forward(type* output,
            type const* data,
            size_t width,
            size_t height,
            size_t depth,
            size_t num,
            size_t normDepth,
            type kappa, type alpha, type beta)
    {
      int t ;
      int m1 = ((signed)normDepth-1)/2 ;
      int m2 = (int)normDepth - m1 - 1 ;
      int offset = (int)width*(int)height ;
#ifndef VL_NNNORMALIZE_FAST
      for (int k = 0 ; k < num ; ++k) {
        for (int h = 0 ; h < height ; ++h) {
          for (int w = 0 ; w < width ; ++w) {
            type const* x = data + w + h * width ;
            T* y = output + w + h * width ;
            type acc = 0 ;
            for (t = -m2 ; t < (signed)depth ; ++t) {
              type ap = 0 ;
              type am = 0 ;
              if (t-m1-1 >= 0) { am = xat(t-m1-1) ; }
              if (t+m2 < depth) { ap = xat(t+m2) ; }
              acc += ap*ap - am*am ;
              if (0 <= t && t < depth) {
                yat(t) = xat(t) * fast_pow(kappa + alpha * acc, -beta) ;
              }
            }
          }
        }
        data += width*height*depth ;
        output += width*height*depth ;
      }
#else
      type * acc = (type*) calloc(sizeof(type), width*height) ;
      for (int k = 0 ; k < num ; ++k) {
        memset(acc, 0, sizeof(type) * width*height) ;
        for (t = -m2 ; t < (signed)depth ; ++t) {
          int tm = t - m1 - 1 ;
          int tp = t + m2 ;
          type const* xam = data + offset * (t-m1-1) ;
          type const* xap = data + offset * (t+m2) ;
          type *end = acc + width*height ;
          if (0 <= tm && tp < depth) {
            for(type *xacc = acc ; xacc != end ; ++xacc, ++xam, ++xap) {
              type am = *xam ;
              type ap = *xap ;
              *xacc += ap*ap - am*am ;
            }
          } else if (0 > tm && tp < depth) {
            for(type *xacc = acc ; xacc != end ; ++xacc, ++xap) {
              type ap = *xap ;
              *xacc += ap*ap ;
            }
          } else if (0 <= tm && tp >= depth) {
            for(type *xacc = acc ; xacc != end ; ++xacc, ++xam) {
              type am = *xam ;
              *xacc -= am*am ;
            }
          }
          if (0 <= t && t < depth) {
            type const* xx = data + offset * t ;
            type * xy = output + offset * t ;
            for(type *xacc = acc ; xacc != end ; ++xacc, ++xx, ++xy) {
              (*xy) = (*xx) * fast_pow(kappa + alpha * (*xacc), -beta) ;
            }
          }
        }
        data += width*height*depth ;
        output += width*height*depth ;
      }
      free(acc) ;
#endif
      return vl::VLE_Success ;
    }
Exemplo n.º 16
0
int main() {
    double x = 0.0l, y = -100.0l;

#if 0
    printf("fast_pow(%g,%g) = %g\n", x,y,fast_pow(x,y));
    printf("pow(%g,%g) = %g\n", x,y,pow(x,y));
#else
    struct tms ti, tf;
    double i =0, k=0, mink = 100, maxk = 110, min = -150, max = 150;

//#  if 1
    double total_err = 0.0, err = 0.0, t1,t2;
    for (k = mink; k < maxk; k+=0.01) {
	if (k == 0 && i <= 0) continue;
	for (i = min; i < max; i+=0.01) {
	    t1 = pow (k,i);
	    t2 = fast_pow (k, i);
	    total_err += err = fabs((t1 - t2)/t1);
	    //printf("%g\t%g\t%g\t%g\n", i, err, t1, t2);
	}
    }

    fprintf(stderr,"total error sum((pow(..) - fast_pow(..))/pow(..)) is %g\n", total_err);
//#  else
    double sum = 0.0;

    times(&ti);
    for (k = mink; k < maxk; k+=0.01) {
	if (k == 0 && i <= 0) continue;
	for (i = min; i < max; i+=0.01) {
	    t2 = fast_pow (k, i);
            sum += t2;
	}
    }
    times(&tf);

    double duration = difftms(tf,ti);

    printf ("fast_pow : \n");
    printf ("sum is %.3f\n", sum);
    printf ("Elapsed time = %.3f s\n", duration);


    sum = 0.0;

    times(&ti);
    for (k = mink; k < maxk; k+=0.01) {
	if (k == 0 && i <= 0) continue;
	for (i = min; i < max; i+=0.01) {
	    t1 = pow (k, i);
            sum += t1;
	}
    }
    times(&tf);

    duration = difftms(tf,ti);

    printf ("pow : \n");
    printf ("sum is %.3f\n", sum);
    printf ("Elapsed time = %.3f s\n", duration);
//#  endif
#endif
    fflush(stdout);

    return 0;
}