int main() { int t,n; ull temp,temp1=fastpow(25,MOD-2); scanf("%d",&t); while(t--) { scanf("%d",&n); if(n%2==0) temp=(((52*(fastpow(26,n/2)-1))%MOD)*temp1)%MOD; else { n--; temp=(((52*(fastpow(26,n/2)-1))%MOD)*temp1)%MOD; temp=((temp+fastpow(26,n/2+1)%MOD); } printf("%lld\n",temp); /* if(n%2==0) a=52 r=26 a*(r^n-1)/(r-1) else n--; 26^(n/2+1) */ } return 0; }
void PidControllerMakeLut() { int16_t i; float x; for(i=0;i<PIDLIB_LUT_SIZE;i++) { // check for valid power base if( PIDLIB_LUT_FACTOR > 1 ) { x = fastpow( PIDLIB_LUT_FACTOR, (float)i / (float)(PIDLIB_LUT_SIZE-1) ); if(i >= (PIDLIB_LUT_OFFSET/2)) PidDriveLut[i] = (((x - 1.0) / (PIDLIB_LUT_FACTOR - 1.0)) * (PIDLIB_LUT_SIZE-1-PIDLIB_LUT_OFFSET)) + PIDLIB_LUT_OFFSET; else PidDriveLut[i] = i * 2; } else { // Linear PidDriveLut[i] = i; } } }
double AnovaDotKernel::operator () (const vector<double> &x, const vector<double> &y) const { assert(x.size() == y.size()); double acc = 0.0; for(size_t i=0; i<x.size(); ++i) { acc += fastexp(-o.sigma*(x[i] - y[i])*(x[i] - y[i])); } return fastpow(acc, o.power); }
int main() { int T; scanf("%d", &T); for (int i = 1; i <= T; i++) { printf("Case #%d:\n", i); int x, m, k, c; scanf("%d%d%d%d", &x, &m, &k, &c); int ans = (fastpow(10, m, 9 * k) - 1) / 9 * x % k; if (ans == c) printf("Yes\n"); else printf("No\n"); } return 0; }
int primitive_root(const int p) { if (p == 2) return 1; int cnt = 0, m = p-1; for (int i = 2; i*i <= m; ++ i) if (m%i == 0) { divs[cnt++] = i; if (i*i < m) divs[cnt++] = m/i; } int r = 2, j = 0; while (1) { for (j = 0; j < cnt; ++ j) { if (fastpow(r, divs[j], p) == 1) break; } if (j >= cnt) return r; r ++; } return -1; }
int BabyStep(int A,int B,int C){ top=maxn;++idx; ll buf=1%C,D=buf,K=0; int i,d=0,tmp; for (i=0;i<=100;buf=buf*A%C,++i) if (buf==B) return i; while ((tmp=gcd(A,C))!=1){ if (B%tmp) return -1; ++d; C/=tmp; B/=tmp; D=D*A/tmp%C; } int M=(int)ceil(sqrt(double(C))); for (buf=1%C,i=0;i<=M;buf=buf*A%C,++i) insert(i,buf); for (int i=0,K=fastpow(A,M,C);i<=M;D=D*K%C,++i){ tmp=Inval(int(D),B,C);int w; if (tmp>0&&(w=find(tmp))!=-1) return i*M+w+d; } return -1; }
/******************************************************************* the coefficients b(i), c(i), and d(i) are computed for a cubic interpolating spline s(x) = y(i) + b(i)*(x-x(i)) + c(i)*(x-x(i))**2 + d(i)*(x-x(i))**3 for x(i) .le. x .le. x(i+1) input.. n = the number of data points or knots (n.ge.2) x = the abscissas of the knots in strictly increasing order y = the ordinates of the knots output.. b, c, d = arrays of spline coefficients as defined above. using p to denote differentiation, y(i) = s(x(i)) b(i) = sp(x(i)) c(i) = spp(x(i))/2 d(i) = sppp(x(i))/6 (derivative from the right) the accompanying function subprogram seval can be used to evaluate the spline. *******************************************************************/ void CubicSpline::computeCoefficents() { if (n < 2) { printf("Dimension can not be less than 3 in spline"); abort(); } if (n == 2) { bb[0] = (yy[1] - yy[0]) / (xx[1] - xx[0]); cc[0] = 0.0; dd[0] = 0.0; bb[1] = bb[0]; cc[1] = 0.0; dd[1] = 0.0; } else { /*************************************************** set up tridiagonal system b = diagonal, d = offdiagonal, c = right hand side. ****************************************************/ dd[0] = xx[1] - xx[0]; cc[1] = (yy[1] - yy[0]) / dd[0]; for (size_t i = 1; i < n - 1; i++) { dd[i] = xx[i + 1] - xx[i]; bb[i] = 2.0 * (dd[i - 1] + dd[i]); cc[i + 1] = (yy[i + 1] - yy[i]) / dd[i]; cc[i] = cc[i + 1] - cc[i]; } /****************************************************** end conditions. third derivatives at x[1] and x[n] obtained from divided differences ******************************************************/ bb[0] = -dd[0]; bb[n - 1] = -dd[n - 2]; cc[0] = 0.0; cc[n - 1] = 0.0; if (n > 3) { cc[0] = cc[2] / (xx[3] - xx[1]) - cc[1] / (xx[2] - xx[0]); cc[n - 1] = cc[n - 2] / (xx[n - 1] - xx[n - 3]) - cc[n - 3] / (xx[n - 2] - xx[n - 4]); cc[0] = cc[0] * fastpow(dd[0], 2) / (xx[3] - xx[0]); cc[n - 1] = -cc[n - 1] * fastpow(dd[n - 2], 2) / (xx[n - 1] - xx[n - 4]); } // *** forward elimination double t; for (size_t i = 1; i < n; i++) { t = dd[i - 1] / bb[i - 1]; bb[i] = bb[i] - t * dd[i - 1]; cc[i] = cc[i] - t * cc[i - 1]; } // *** back substitution cc[n - 1] = cc[n - 1] / bb[n - 1]; for (size_t ib = 0; ib < n - 1; ib++) { size_t i = n - 1 - ib; cc[i] = (cc[i] - dd[i] * cc[i + 1]) / bb[i]; } // // c[i] is now the sigma[i] of the text // // compute polynomial coefficients // bb[n - 1] = (yy[n - 1] - yy[n - 1 - 1]) / dd[n - 1 - 1] + dd[n - 1 - 1] * (cc[n - 1 - 1] + 2.0 * cc[n - 1]); for (size_t i = 0; i < n - 1; i++) { bb[i] = (yy[i + 1] - yy[i]) / dd[i] - dd[i] * (cc[i + 1] + 2.0 * cc[i]); dd[i] = (cc[i + 1] - cc[i]) / dd[i]; cc[i] = 3.0 * cc[i]; } cc[n - 1] = 3.0 * cc[n - 1]; dd[n - 1] = dd[n - 2]; } }
int inv(int a) { return fastpow(a, MOD-2); }
int main() { a = exp(a); b = expf(b); c = fastexp(c); d = fasterexp(c); printf("%f %f %f %f\n", a, b, c, d); a = log(a); b = logf(b); c = fastlog(c); d = fasterlog(c); printf("%f %f %f %f\n", a, b, c, d); a = pow(a,a); b = pow(b,b); c = fastpow(c,c); d = fasterpow(c,c); printf("%f %f %f %f\n", a, b, c, d); a = sin(a); b = sinf(b); c = fastsin(c); d = fastersin(c); printf("%f %f %f %f\n", a, b, c, d); a = cos(a); b = cosf(b); c = fastcos(c); d = fastercos(c); printf("%f %f %f %f\n", a, b, c, d); a = tan(a); b = tanf(b); c = fasttan(c); d = fastertan(c); printf("%f %f %f %f\n", a, b, c, d); a = asin(a); b = asinf(b); printf("%f %f %f %f\n", a, b, c, d); a = acos(a); b = acosf(b); printf("%f %f %f %f\n", a, b, c, d); a = atan(a); b = atanf(b); printf("%f %f %f %f\n", a, b, c, d); a = sinh(a); b = sinhf(b); c = fastsinh(c); d = fastersinh(c); printf("%f %f %f %f\n", a, b, c, d); a = cosh(a); b = coshf(b); c = fastcosh(c); d = fastercosh(c); printf("%f %f %f %f\n", a, b, c, d); a = tanh(a); b = tanhf(b); c = fasttanh(c); d = fastertanh(c); printf("%f %f %f %f\n", a, b, c, d); a = lgamma(a); b = lgammaf(b); c = fastlgamma(c); d = fasterlgamma(c); printf("%f %f %f %f\n", a, b, c, d); return 0; }
static scalar get_sun_intensity( const vector &ray_dir, const vector &sun_dir, scalar haze, scalar sun_disk_size, scalar sun_disk_intensity, scalar sun_glow_size, scalar sun_glow_intensity, scalar sun_glow_falloff) { sun_disk_size *= 0.0465f; sun_glow_size *= 0.0465f; scalar sun_total_size = sun_disk_size + sun_glow_size; scalar intensity = 1.0f; scalar gamma = acosf(dot(ray_dir, sun_dir)); if (gamma < sun_total_size) { scalar r = 1.0f - gamma / sun_total_size; intensity += sun_disk_intensity * smoothstep(0.0f, haze * 2.0f, r) + sun_glow_intensity * fastpow(r, sun_glow_falloff * haze); if (gamma < sun_disk_size) { intensity += sun_disk_intensity; } } return intensity; }