int getResult(int n1, int n2, int n3, int k) { int LCM12, LCM23, LCM31, LCM123, result, rem1, rem2, rem3; if (n1<0 || n2<0 || n3<0) return -1; //Error Condition LCM12 = LCM(n1, n2, 1); LCM23 = LCM(1, n2, n3); LCM31 = LCM(n1, 1, n3); LCM123 = LCM(n1, n2, n3); result = (k*LCM123) / ((LCM123 / n1) + (LCM123 / n2) + (LCM123 / n3) - (LCM123 / LCM12) - (LCM123 / LCM23) - (LCM123 / LCM31) + 1); //Main Formula if ((result / n1) + (result / n2) + (result / n3) - (result / LCM12) - (result / LCM23) - (result / LCM31) + (result / LCM123) < k) { rem1 = n1 - result%n1; rem2 = n2 - result%n2; rem3 = n3 - result%n3; return result + (rem1 < rem2 ? (rem1 < rem3 ? rem1 : rem3) : (rem2 < rem3 ? rem2 : rem3)); } else { rem1 = result%n1; rem2 = result%n2; rem3 = result%n3; return result - (rem1 < rem2 ? (rem1 < rem3 ? rem1 : rem3) : (rem2 < rem3 ? rem2 : rem3)); } }
quantList makequantList(FractList frList, double ori, RubatoFract msh, BOOL Automatic) { int i; int *num = calloc(frList.length, sizeof(int)); int *denom = calloc(frList.length, sizeof(int)); int *oo = NULL; int *ons = NULL; quantList QL = {0,{1,0,0},oo,0}; ons = num; /*denom = calloc(frList.length, sizeof(int)); num = calloc(frList.length, sizeof(int));*/ for(i = 0;i < frList.length;i++) { *(denom+i) = (frList.Fronsets+i)->denominator; *(num+i) = (frList.Fronsets+i)->numerator; } if( !msh.isFraction || /*Double method*/ (msh.isFraction && ori) || (msh.isFraction && !ori && !ISFr(frList)) || (msh.isFraction && !ori && ISFr(frList) && !Automatic) ) { for(i = 0;i < frList.length;i++) *(ons+i) = gridOnset(ori,msh,*(frList.Fronsets+i)); } else /*Fraction method for Automatic grid re-definition*/ { for(i = 0;i < frList.length;i++) *(num+i) *= LCM(denom, frList.length)/(frList.Fronsets+i)->denominator; msh.numerator = LCD(num, frList.length); msh.denominator = LCM(denom, frList.length); for(i = 0;i < frList.length;i++) *(ons+i) = *(num+i)/LCD(num, frList.length); } QL.origin = ori; QL.mesh = msh; QL.onsets = ons; QL.length = frList.length; return clean(QL); }
int main () { uint32_t Number = 7868025; uint32_t GCDReturn; uint32_t LCMReturn; // Call assembly Fermat from C Fermitfactors Factors_1 = {0, 0}; CallAssembly(Number, 1); // Call C-Fermat from C Factors_1 = factorization (Number); // Call Prime Factorization from C Primefactorization(Number); printf("\nC: f1: %d \t C: f2: %d\n", Factors_1.f1, Factors_1.f2); //Call GCD GCDReturn = GCD(13, 17); printf("The result of GCD is %d\n", GCDReturn); //Call LCM LCMReturn = LCM(5, 25); printf("The result of LCM is %d\n", LCMReturn); return 0; }
bool InvertibleRSAFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const { bool pass = RSAFunction::Validate(rng, level); CRYPTOPP_ASSERT(pass); pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n; CRYPTOPP_ASSERT(pass); pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n; CRYPTOPP_ASSERT(pass); pass = pass && m_d > Integer::One() && m_d.IsOdd() && m_d < m_n; CRYPTOPP_ASSERT(pass); pass = pass && m_dp > Integer::One() && m_dp.IsOdd() && m_dp < m_p; CRYPTOPP_ASSERT(pass); pass = pass && m_dq > Integer::One() && m_dq.IsOdd() && m_dq < m_q; CRYPTOPP_ASSERT(pass); pass = pass && m_u.IsPositive() && m_u < m_p; CRYPTOPP_ASSERT(pass); if (level >= 1) { pass = pass && m_p * m_q == m_n; CRYPTOPP_ASSERT(pass); pass = pass && m_e*m_d % LCM(m_p-1, m_q-1) == 1; CRYPTOPP_ASSERT(pass); pass = pass && m_dp == m_d%(m_p-1) && m_dq == m_d%(m_q-1); CRYPTOPP_ASSERT(pass); pass = pass && m_u * m_q % m_p == 1; CRYPTOPP_ASSERT(pass); } if (level >= 2) { pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2); CRYPTOPP_ASSERT(pass); } return pass; }
/** Method used by the root process to calculate the final lcm obtained from all the processes.*/ int lcm_local_operation(int *vals_array,int len) { int lcm_res = vals_array[0]; for(i=1;i<len;i++) { lcm_res = LCM(lcm_res,vals_array[i]); } return lcm_res; }
// generate a random private key InvertableRSAFunction::InvertableRSAFunction(RandomNumberGenerator &rng, unsigned int keybits, const Integer &eStart) { assert(keybits >= 16); // generate 2 random primes of suitable size if (keybits%2==0) { const Integer minP = Integer(182) << (keybits/2-8); const Integer maxP = Integer::Power2(keybits/2)-1; p.Randomize(rng, minP, maxP, Integer::PRIME); q.Randomize(rng, minP, maxP, Integer::PRIME); } else { const Integer minP = Integer::Power2((keybits-1)/2); const Integer maxP = Integer(181) << ((keybits+1)/2-8); p.Randomize(rng, minP, maxP, Integer::PRIME); q.Randomize(rng, minP, maxP, Integer::PRIME); } // pre-calculate some other data for faster speed const Integer lcm = LCM(p-1, q-1); // make sure e starts odd for (e = eStart+(1-eStart%2); GCD(e, lcm)!=1; ++e, ++e); d = EuclideanMultiplicativeInverse(e, lcm); dp = d % (p-1); dq = d % (q-1); u = EuclideanMultiplicativeInverse(q, p); n = p * q; assert(n.BitCount() == keybits); }
void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) { int modulusSize = 2048; alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); ASSERT( modulusSize >= 16 ); m_e = alg.GetValueWithDefault("PublicExponent", Integer(17)); ASSERT( m_e >= 3 ); ASSERT( !m_e.IsEven() ); RSAPrimeSelector selector(m_e); const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) ("PointerToPrimeSelector", selector.GetSelectorPointer()); m_p.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam); m_d = EuclideanMultiplicativeInverse(m_e, LCM(m_p-1, m_q-1)); assert(m_d.IsPositive()); m_dp = m_d % (m_p-1); m_dq = m_d % (m_q-1); m_n = m_p * m_q; m_u = m_q.InverseMod(m_p); }
int main() { int a = 3234; int b = 234; printf("最小公倍数:%d\n",LCM(a,b)); printf("最大公约数:%d\n",GCD(a,b)); }
//Computes the S-polynomial of two polynomials and returns it Polynomial syzygy(Polynomial a, Polynomial b, int(*compar)(const Monomial, const Monomial)) { Monomial gcd = LCM(a.poly[0], b.poly[0]); Monomial neg = gcd; neg.coeff.numer = -1; Polynomial ret = add(gcd / a.poly[0] * a, neg / b.poly[0] * b, compar); return ret; }
int LCM_N_Numbers(int a[]) { int i = 0; for(i=0; i<N-1; i++) { a[i+1] = LCM(a[i],a[i+1]); } return a[i]; }
InvertableRSAFunction::InvertableRSAFunction(const Integer &n, const Integer &e, const Integer &d, const Integer &p, const Integer &q, const Integer &dp, const Integer &dq, const Integer &u) : RSAFunction(n, e), d(d), p(p), q(q), dp(dp), dq(dq), u(u) { assert(p*q==n); assert(d*e%LCM(p-1, q-1)==1); assert(dp==d%(p-1)); assert(dq==d%(q-1)); assert(u*q%p==1); }
double LCM_N_Numbers(double a[]) { int i = 0; for(i=0; i<N-1; i++) { a[i+1] = LCM(a[i],a[i+1]); printf("a[%d] = %f\n",i+1, a[i+1]); } return a[i]; }
/* 暗号化 */ void An(void) { //p,q:素数,n:pq,M:平文,e:公開鍵,C:暗号文,d:秘密鍵 int p, q, n, r, M, e, d = 0; double C; printf("STEP1:平文Mを入力>"); scanf_s("%d", &M); printf("平文M=%dとして計算します.\n", M); printf("STEP2:2つの素数の入力\n"); for (int i = 0; i < 2; i++) { while (1) { printf("%dつ目の素数を入力してください.>", i + 1); scanf_s("%d", &q); if (Prime(q) == 0){ printf("素数であると確認しました.\n"); break; } else if (Prime(q) == 1){ printf("\n素数ではありません.\n"); } else{ perror("判定不能\n"); } } if (i < 1) { p = q; } } printf("\n1つ目の素数p=%d\n2つ目の素数q=%d \n", p, q); n = p*q; r = LCM(p - 1, q - 1); printf("公開鍵n:%d \n", n); //printf("演算補助の商r(n):%d ", r); //eを決定 for (e = 2; e < r; e++){ if (GCD(e, r, 0) == 1){ //printf("公開鍵e=%d として計算します.\n\n", e); break; } } //dを決定 d = GCD(r, e, 1); if (d < 0) { d += r; } printf("暗号化結果\n秘密鍵d:%d\n", d); C = fmod(pow(M, e), n); printf("暗号文C:%.0lf\n", C); }
int main() { int lcmVar = 1; int i = 1; for(; i < 20; ++i) { lcmVar = LCM(lcmVar, i); } printf("%d\n", lcmVar); }
int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { int a,b; scanf("%d%d",&a,&b); printf("%d %d %d\n",i+1,LCM(a,b),GCD(a,b)); } return 0; }
int main() { int num0 = 0; int num1 = 0; printf("Please enter number 0: "); num0 = GetInteger(); printf("Please enter number 1: "); num1 = GetInteger(); int lcm = LCM(num0, num1); printf("The lease common multiple is: %d \n", lcm); return 0; }
// generate RSA keypair void AsymmCipher::genkeypair(Integer* privk, Integer* pubk, int size) { pubk[PUB_E] = 17; RSAPrimeSelector selector(pubk[PUB_E]); AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(size)(Name::PointerToPrimeSelector(),selector.GetSelectorPointer()); privk[PRIV_P].GenerateRandom(PrnGen::rng,primeParam); privk[PRIV_Q].GenerateRandom(PrnGen::rng,primeParam); privk[PRIV_D] = pubk[PUB_E].InverseMod(LCM(privk[PRIV_P]-Integer::One(),privk[PRIV_Q]-Integer::One())); pubk[PUB_PQ] = privk[PRIV_P]*privk[PRIV_Q]; privk[PRIV_U] = privk[PRIV_P].InverseMod(privk[PRIV_Q]); }
int main() { char s[30]; int j,flag; long long product; while(1) { scanf("%s",s); if(s[0]=='*') break; //gcd=-1; product=1; flag=1; j=0; for(int i=0; s[i]!='\0' ; i++) { j++; if(s[i]=='Y') { product=LCM(product,j); } } for(int i=0; s[i]!='\0' ; i++) { if(s[i]=='N') { if(product%(i+1)==0) { printf("-1\n"); flag=0; break; } } } if(flag) printf("%lld\n",product); } return 0; }
void freeinit(Freelist * fl, int size) { fl->head = NULL; fl->nodesize = LCM(size, sizeof(Freenode)); if (fl->blocklist != NULL) { Freeblock *bp, *np; bp = fl->blocklist; while (bp != NULL) { np = bp->next; free(bp->nodes); free(bp); bp = np; } } fl->blocklist = NULL; }
Fraction Fraction::operator += (const Fraction& rhs) { const int lcm = LCM(DenominatorAsInt(), rhs.DenominatorAsInt()); int A = 0, B = 0; if (__builtin_mul_overflow(numerator / DenominatorAsInt(), lcm, &A)) goto err; if (__builtin_mul_overflow(rhs.numerator / rhs.DenominatorAsInt(), lcm, &B)) goto err; if (__builtin_add_overflow(A, B, &numerator)) goto err; denominator = lcm; Reduce(); return *this; err: valid = false; return *this; }
Fraction Fraction::operator -= (const Fraction& rhs) { const int lcm = LCM(DenominatorAsInt(), rhs.DenominatorAsInt()); int A = 0, B = 0; if (__builtin_mul_overflow(numerator / DenominatorAsInt(), lcm, &A)) goto err; if (__builtin_mul_overflow(rhs.numerator / rhs.DenominatorAsInt(), lcm, &B)) goto err; if (__builtin_sub_overflow(A, B, &numerator)) goto err; denominator = lcm; Reduce(); // std::cout << "result: " << *this << std::endl; return *this; err: valid = false; return *this; }
void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) { int modulusSize = 2048; alg.GetIntValue(Name::ModulusSize(), modulusSize) || alg.GetIntValue(Name::KeySize(), modulusSize); assert(modulusSize >= 16); if (modulusSize < 16) throw InvalidArgument("InvertibleRSAFunction: specified modulus size is too small"); m_e = alg.GetValueWithDefault(Name::PublicExponent(), Integer(17)); assert(m_e >= 3); assert(!m_e.IsEven()); if (m_e < 3 || m_e.IsEven()) throw InvalidArgument("InvertibleRSAFunction: invalid public exponent"); RSAPrimeSelector selector(m_e); AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) (Name::PointerToPrimeSelector(), selector.GetSelectorPointer()); m_p.GenerateRandom(rng, primeParam); m_q.GenerateRandom(rng, primeParam); m_d = m_e.InverseMod(LCM(m_p-1, m_q-1)); assert(m_d.IsPositive()); m_dp = m_d % (m_p-1); m_dq = m_d % (m_q-1); m_n = m_p * m_q; m_u = m_q.InverseMod(m_p); if (FIPS_140_2_ComplianceEnabled()) { RSASS<PKCS1v15, SHA>::Signer signer(*this); RSASS<PKCS1v15, SHA>::Verifier verifier(signer); SignaturePairwiseConsistencyTest_FIPS_140_Only(signer, verifier); RSAES<OAEP<SHA> >::Decryptor decryptor(*this); RSAES<OAEP<SHA> >::Encryptor encryptor(decryptor); EncryptionPairwiseConsistencyTest_FIPS_140_Only(encryptor, decryptor); } }
//Generates the groebner basis using buchberger's algorithm without any improvements (i.e. polynomial pruning to create minimal or reduced groebner basis) //Create a list of pairs, one for each combination of polynomial's. //Then compute the syzygy polynomial. Divide it by the ideal polynomials. If the remainder is not zero, then add the polynomial and the new pairs into the list. void Ideal::Groebner1() { int t = gen.size(); queue<int> l1, l2; for (int i = 0; i < t; i++) { for (int j = i; j < t; j++) { l1.push(i); l2.push(j); } } //The selection of the pair is just iterative, using a queue int inc = 0;//Increment this over the size of the list to obtain all pairs while (l1.size() > 0) { Polynomial p1 = gen[l1.front()]; Polynomial p2 = gen[l2.front()]; l1.pop(), l2.pop();//Pop the pair Monomial l = LCM(p1.poly[0], p2.poly[0]); Monomial m = p1.poly[0] * p2.poly[0]; if (!equal(m, l)) { Polynomial s = syzygy(p1, p2, compar); Polynomial rem = divR(s); if (rem.poly.size() != 0) { for (int i = 0; i < t; i++) { l1.push(i); l2.push(t); } gen.push_back(rem); t++;//There is now another polynomial } } } }
BigInt BigInt::PolardP_1_get_factor(BigInt N, BigInt a) { BigInt d, k, t; ll K=10 ; k = LCM(K); int max_iter = 234; int i = 1; for (;; i++) { if (gcd(a, N) > 1) return gcd(a, N); t = PowModN(a, k, N); d = gcd(t - 1, N); if (d > 1 && d< N) return d; else { vector<int> deltas = Polard_Help_Eratosfen(K, K * K-K+2); BigInt q0; q0 = (long long)deltas.back(); deltas.pop_back(); BigInt c = PowModN(t, q0, N); for (int i = 1; i < deltas.size(); i++) { d = gcd(c-1, N); if (d == 1) { BigInt q; q = (long long)deltas[i - 1]; c = c*PowModN(t, q, N); } else return d; } } } }
int main() { LL n, m; LL divisor[20]; while (scanf("%lld %lld", &n, &m) != EOF) { for (LL i = 0; i < m; ++i) scanf("%lld", &divisor[i]); LL sum = 0; LL sign = 1, great = 1; for (LL i = 1; i < (1 << m); ++i) { great = 1; sign = -1; for (LL j = 0; j < m; ++j) if ((1<<j) & i) { great = LCM(great, divisor[j]); sign *= -1; } sum += sign * (n / great); sign *= -1; } printf("%lld\n", n - sum); } return 0; }
int picture_Setup( picture_t *p_picture, video_format_t *fmt ) { /* Store default values */ p_picture->i_planes = 0; for( unsigned i = 0; i < VOUT_MAX_PLANES; i++ ) { plane_t *p = &p_picture->p[i]; p->p_pixels = NULL; p->i_pixel_pitch = 0; } atomic_init( &p_picture->gc.refcount, 0 ); p_picture->gc.pf_destroy = NULL; p_picture->gc.p_sys = NULL; p_picture->i_nb_fields = 2; video_format_Setup( &p_picture->format, fmt->i_chroma, fmt->i_width, fmt->i_height, fmt->i_visible_width, fmt->i_visible_height, fmt->i_sar_num, fmt->i_sar_den ); const vlc_chroma_description_t *p_dsc = vlc_fourcc_GetChromaDescription( p_picture->format.i_chroma ); if( !p_dsc ) return VLC_EGENERIC; /* We want V (width/height) to respect: (V * p_dsc->p[i].w.i_num) % p_dsc->p[i].w.i_den == 0 (V * p_dsc->p[i].w.i_num/p_dsc->p[i].w.i_den * p_dsc->i_pixel_size) % 16 == 0 Which is respected if you have V % lcm( p_dsc->p[0..planes].w.i_den * 16) == 0 */ int i_modulo_w = 1; int i_modulo_h = 1; unsigned int i_ratio_h = 1; for( unsigned i = 0; i < p_dsc->plane_count; i++ ) { i_modulo_w = LCM( i_modulo_w, 16 * p_dsc->p[i].w.den ); i_modulo_h = LCM( i_modulo_h, 16 * p_dsc->p[i].h.den ); if( i_ratio_h < p_dsc->p[i].h.den ) i_ratio_h = p_dsc->p[i].h.den; } i_modulo_h = LCM( i_modulo_h, 32 ); const int i_width_aligned = ( fmt->i_width + i_modulo_w - 1 ) / i_modulo_w * i_modulo_w; const int i_height_aligned = ( fmt->i_height + i_modulo_h - 1 ) / i_modulo_h * i_modulo_h; const int i_height_extra = 2 * i_ratio_h; /* This one is a hack for some ASM functions */ for( unsigned i = 0; i < p_dsc->plane_count; i++ ) { plane_t *p = &p_picture->p[i]; p->i_lines = (i_height_aligned + i_height_extra ) * p_dsc->p[i].h.num / p_dsc->p[i].h.den; p->i_visible_lines = fmt->i_visible_height * p_dsc->p[i].h.num / p_dsc->p[i].h.den; p->i_pitch = i_width_aligned * p_dsc->p[i].w.num / p_dsc->p[i].w.den * p_dsc->pixel_size; p->i_visible_pitch = fmt->i_visible_width * p_dsc->p[i].w.num / p_dsc->p[i].w.den * p_dsc->pixel_size; p->i_pixel_pitch = p_dsc->pixel_size; assert( (p->i_pitch % 16) == 0 ); } p_picture->i_planes = p_dsc->plane_count; return VLC_SUCCESS; }
static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo) { struct fb_info *psLINFBInfo; struct module *psLINFBOwner; OMAPLFB_FBINFO *psPVRFBInfo = &psDevInfo->sFBInfo; OMAPLFB_ERROR eError = OMAPLFB_ERROR_GENERIC; unsigned long FBSize; unsigned long ulLCM; unsigned uiFBDevID = psDevInfo->uiFBDevID; acquire_console_sem(); psLINFBInfo = registered_fb[uiFBDevID]; if (psLINFBInfo == NULL) { eError = OMAPLFB_ERROR_INVALID_DEVICE; goto ErrorRelSem; } FBSize = (psLINFBInfo->screen_size) != 0 ? psLINFBInfo->screen_size : psLINFBInfo->fix.smem_len; if (FBSize == 0 || psLINFBInfo->fix.line_length == 0) { eError = OMAPLFB_ERROR_INVALID_DEVICE; goto ErrorRelSem; } psLINFBOwner = psLINFBInfo->fbops->owner; if (!try_module_get(psLINFBOwner)) { printk(KERN_INFO DRIVER_PREFIX ": %s: Device %u: Couldn't get framebuffer module\n", __FUNCTION__, uiFBDevID); goto ErrorRelSem; } if (psLINFBInfo->fbops->fb_open != NULL) { int res; res = psLINFBInfo->fbops->fb_open(psLINFBInfo, 0); if (res != 0) { printk(KERN_INFO DRIVER_PREFIX " %s: Device %u: Couldn't open framebuffer(%d)\n", __FUNCTION__, uiFBDevID, res); goto ErrorModPut; } } psDevInfo->psLINFBInfo = psLINFBInfo; ulLCM = LCM(psLINFBInfo->fix.line_length, OMAPLFB_PAGE_SIZE); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer physical address: 0x%lx\n", psDevInfo->uiFBDevID, psLINFBInfo->fix.smem_start)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer virtual address: 0x%lx\n", psDevInfo->uiFBDevID, (unsigned long)psLINFBInfo->screen_base)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer size: %lu\n", psDevInfo->uiFBDevID, FBSize)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer virtual width: %u\n", psDevInfo->uiFBDevID, psLINFBInfo->var.xres_virtual)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer virtual height: %u\n", psDevInfo->uiFBDevID, psLINFBInfo->var.yres_virtual)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer width: %u\n", psDevInfo->uiFBDevID, psLINFBInfo->var.xres)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer height: %u\n", psDevInfo->uiFBDevID, psLINFBInfo->var.yres)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Framebuffer stride: %u\n", psDevInfo->uiFBDevID, psLINFBInfo->fix.line_length)); DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: LCM of stride and page size: %lu\n", psDevInfo->uiFBDevID, ulLCM)); psPVRFBInfo->sSysAddr.uiAddr = psLINFBInfo->fix.smem_start; psPVRFBInfo->sCPUVAddr = psLINFBInfo->screen_base; psPVRFBInfo->ulWidth = psLINFBInfo->var.xres; psPVRFBInfo->ulHeight = psLINFBInfo->var.yres; psPVRFBInfo->ulByteStride = psLINFBInfo->fix.line_length; psPVRFBInfo->ulFBSize = FBSize; psPVRFBInfo->ulBufferSize = psPVRFBInfo->ulHeight * psPVRFBInfo->ulByteStride; psPVRFBInfo->ulRoundedBufferSize = RoundUpToMultiple(psPVRFBInfo->ulBufferSize, ulLCM); if(psLINFBInfo->var.bits_per_pixel == 16) { if((psLINFBInfo->var.red.length == 5) && (psLINFBInfo->var.green.length == 6) && (psLINFBInfo->var.blue.length == 5) && (psLINFBInfo->var.red.offset == 11) && (psLINFBInfo->var.green.offset == 5) && (psLINFBInfo->var.blue.offset == 0) && (psLINFBInfo->var.red.msb_right == 0)) { psPVRFBInfo->ePixelFormat = PVRSRV_PIXEL_FORMAT_RGB565; } else { printk(KERN_INFO DRIVER_PREFIX ": %s: Device %u: Unknown FB format\n", __FUNCTION__, uiFBDevID); } } else if(psLINFBInfo->var.bits_per_pixel == 32) { if((psLINFBInfo->var.red.length == 8) && (psLINFBInfo->var.green.length == 8) && (psLINFBInfo->var.blue.length == 8) && (psLINFBInfo->var.red.offset == 16) && (psLINFBInfo->var.green.offset == 8) && (psLINFBInfo->var.blue.offset == 0) && (psLINFBInfo->var.red.msb_right == 0)) { psPVRFBInfo->ePixelFormat = PVRSRV_PIXEL_FORMAT_ARGB8888; } else { printk(KERN_INFO DRIVER_PREFIX ": %s: Device %u: Unknown FB format\n", __FUNCTION__, uiFBDevID); } } else { printk(KERN_INFO DRIVER_PREFIX ": %s: Device %u: Unknown FB format\n", __FUNCTION__, uiFBDevID); } psDevInfo->sFBInfo.ulPhysicalWidthmm = ((int)psLINFBInfo->var.width > 0) ? psLINFBInfo->var.width : 90; psDevInfo->sFBInfo.ulPhysicalHeightmm = ((int)psLINFBInfo->var.height > 0) ? psLINFBInfo->var.height : 54; psDevInfo->sFBInfo.sSysAddr.uiAddr = psPVRFBInfo->sSysAddr.uiAddr; psDevInfo->sFBInfo.sCPUVAddr = psPVRFBInfo->sCPUVAddr; eError = OMAPLFB_OK; goto ErrorRelSem; ErrorModPut: module_put(psLINFBOwner); ErrorRelSem: release_console_sem(); return eError; }
__s32 Display_Fb_Request(__u32 fb_id, __disp_fb_create_para_t *fb_para) { struct fb_info *info = NULL; __s32 hdl = 0; __disp_layer_info_t layer_para; __u32 sel; __u32 xres, yres; unsigned long ulLCM; __u32 num_screens; num_screens = bsp_disp_feat_get_num_screens(); __inf("Display_Fb_Request,fb_id:%d\n", fb_id); if(g_fbi.fb_enable[fb_id]) { __wrn("Display_Fb_Request, fb%d is already requested!\n", fb_id); return DIS_NO_RES; } info = g_fbi.fbinfo[fb_id]; xres = fb_para->width; yres = fb_para->height; if((0 == xres) || (0 == yres)) { __wrn("invalid paras xres(%d, yres(%d) in Display_Fb_Request\n", xres, yres); return DIS_FAIL; } info->var.xoffset = 0; info->var.yoffset = 0; info->var.xres = xres; info->var.yres = yres; info->var.xres_virtual = xres; info->fix.line_length = (fb_para->width * info->var.bits_per_pixel) >> 3; ulLCM = LCM(info->fix.line_length, PAGE_SIZE); info->fix.smem_len = RoundUpToMultiple(info->fix.line_length * fb_para->height, ulLCM) * fb_para->buffer_num; info->var.yres_virtual = info->fix.smem_len / info->fix.line_length; Fb_map_video_memory(info); for(sel = 0; sel < num_screens; sel++) { if(((sel==0) && (fb_para->fb_mode != FB_MODE_SCREEN1)) || ((sel==1) && (fb_para->fb_mode != FB_MODE_SCREEN0))) { __u32 y_offset = 0, src_width = xres, src_height = yres; if(((sel==0) && (fb_para->fb_mode == FB_MODE_SCREEN0 || fb_para->fb_mode == FB_MODE_DUAL_SAME_SCREEN_TB)) || ((sel==1) && (fb_para->fb_mode == FB_MODE_SCREEN1)) || ((sel == fb_para->primary_screen_id) && (fb_para->fb_mode == FB_MODE_DUAL_DIFF_SCREEN_SAME_CONTENTS))) { __disp_tcon_timing_t tt; if(bsp_disp_get_timming(sel, &tt) >= 0) { info->var.pixclock = 1000000000 / tt.pixel_clk; info->var.left_margin = tt.hor_back_porch; info->var.right_margin = tt.hor_front_porch; info->var.upper_margin = tt.ver_back_porch; info->var.lower_margin = tt.ver_front_porch; info->var.hsync_len = tt.hor_sync_time; info->var.vsync_len = tt.ver_sync_time; } info->var.width = bsp_disp_get_screen_physical_width(sel); info->var.height = bsp_disp_get_screen_physical_height(sel); } if(fb_para->fb_mode == FB_MODE_DUAL_SAME_SCREEN_TB) { src_height = yres/ 2; if(sel == 0) { y_offset = yres / 2; } } memset(&layer_para, 0, sizeof(__disp_layer_info_t)); layer_para.mode = fb_para->mode; layer_para.scn_win.width = src_width; layer_para.scn_win.height = src_height; if(fb_para->fb_mode == FB_MODE_DUAL_DIFF_SCREEN_SAME_CONTENTS) { if(sel != fb_para->primary_screen_id) { layer_para.mode = DISP_LAYER_WORK_MODE_SCALER; layer_para.scn_win.width = fb_para->aux_output_width; layer_para.scn_win.height = fb_para->aux_output_height; } else if(fb_para->mode == DISP_LAYER_WORK_MODE_SCALER) { layer_para.scn_win.width = fb_para->output_width; layer_para.scn_win.height = fb_para->output_height; } } else if(fb_para->mode == DISP_LAYER_WORK_MODE_SCALER) { layer_para.scn_win.width = fb_para->output_width; layer_para.scn_win.height = fb_para->output_height; } hdl = bsp_disp_layer_request(sel, layer_para.mode); if(hdl == 0) { __wrn("Display_Fb_Request, ch%d no layer resource\n", sel); Fb_unmap_video_memory(info); return DIS_NO_RES; } layer_para.pipe = 0; layer_para.alpha_en = 1; layer_para.alpha_val = 0xff; layer_para.ck_enable = 0; layer_para.src_win.x = 0; layer_para.src_win.y = y_offset; layer_para.src_win.width = src_width; layer_para.src_win.height = src_height; layer_para.scn_win.x = 0; layer_para.scn_win.y = 0; var_to_disp_fb(&(layer_para.fb), &(info->var), &(info->fix)); layer_para.fb.addr[0] = (__u32)info->fix.smem_start; layer_para.fb.addr[1] = 0; layer_para.fb.addr[2] = 0; layer_para.fb.size.width = fb_para->width; layer_para.fb.size.height = fb_para->height; layer_para.fb.cs_mode = DISP_BT601; layer_para.b_from_screen = 0; bsp_disp_layer_set_para(sel, hdl, &layer_para); bsp_disp_layer_open(sel, hdl); g_fbi.layer_hdl[fb_id][sel] = hdl; } } g_fbi.fb_enable[fb_id] = 1; g_fbi.fb_mode[fb_id] = fb_para->fb_mode; memcpy(&g_fbi.fb_para[fb_id], fb_para, sizeof(__disp_fb_create_para_t)); return DIS_SUCCESS; }
int main(){ #ifdef LOCAL freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif int snum; int casenum = 1; while((scanf("%d", &snum)) > 0 && snum > 0){ int pattern[snum][11], length[snum]; for (int i = 0; i < snum; i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); length[i] = a + b; for(int j = 0; j < length[i]; j++){ // sleep = 0, awaken = 1; if((j-1+c)%(length[i]) < a) pattern[i][j] = 1; else pattern[i][j] = 0; } } // printpatttern(pattern, length, snum); int impossible = 1; int awakenpoint = 0; int i; for(i = 0; i < LCM(length, snum); i++){ int awakennum = 0; for(int j = 0; j < snum; j ++){ if(pattern[j][i%length[j]]){ awakennum ++; } } if(awakennum >= (snum+1)/2){ impossible = 0; awakennum = 0; int status[snum]; for(int j = 0; j < snum; j++){ status[j] = 0; } while(i < LCM(length, snum) && awakennum < snum){ for(int j = 0; j < snum; j++){ if(status[j] == 0 && pattern[j][i%length[j]]){ status[j] = 1; awakennum ++; } } i++; } break; } } printf("Case %d: ", casenum); if(impossible){ printf("-1\n"); } else { printf("%d\n", i); } casenum ++; } return 0; }
main(){ get_input(); check_input_validity(); printf("LCM = %d", LCM(n, m)); getch(); }