Essay-Pre-invitational training-codeforces Round #330 (Div. 2) Question B

Source: Internet
Author: User

Test instructions

The test instructions of this English question is slightly complicated.

Find out how many sequences of numbers are of length n. This sequence can be divided into n/k segments, each with a K-number. The number of K can be changed to a decimal number XI. Requires that the number of each n/k, excluding XI can be divided by AI, excluding the first number of X (including the leading 0) is the case of BI. Ask how many of the remaining combinations are.

Ideas:

I am a twists of this question.     First also did not consider a lot, watching can be violent simulation process, I directly began to knock, a few for the loop knocked out, and then the bug tune a special case to consider, after the start of the tle, when the realization of the complexity is too large, and began to optimize, did (B[i]) * (MMAX/10)-1 ~ (b[i]+1) * (MMAX/10)-1 of the Cycle range optimization, the latter case again timed out, and later felt that should not be violent simulation, notice that a certain range can be divisible by a number of numbers can be calculated by the formula, which is directly computed with the formula to eliminate the For loop, this is only over the problem.

#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#defineMAX (x, Y) (((x) > (y))? (x): (y))#defineMIN (x, Y) ((() < (y))? (x): (y))#defineABS (x) ((x) >0? ( x):-(x))Const intINF =0x7fffffff;Const intn=100000+Ten;Const Long Longmod=1e9+7;intA[n];intB[n];intMain () {//freopen ("OUT.txt", "w", stdout);    intN; intK; CIN>>n>>K; intkk=K; Long Longmmax=1;  while(kk--) Mmax*=Ten;//cout<<mmax;    intnum=n/K;  for(intI=0; i<num; i++) scanf ("%d", A +i);  for(intI=0; i<num; i++) scanf ("%d", B +i); Long Longans=1;  for(intI=0; i<num; i++)    {        Long LongCnt= (mmax-1)/a[i]+1; if(B[i] = =0) {CNT-= (mmax/Ten-1)/a[i]+1; }        Else{cnt=cnt-(((b[i]+1) * (mmax/Ten)-1)/a[i]+1) + (((B[i]) * (mmax/Ten)-1)/a[i]+1 ); } ans=ans*cnt%MoD; } cout<<ans<<Endl; return 0;}

Essay-Pre-invitational training-codeforces Round #330 (Div. 2) Question B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.