[CSP-S Simulation Test]: Smooth (Mathematics)

Topic Portal (internal title 84)


Input Format

Two integers $ B, K $


Output Format

An integer that represents the answer


Sample

Sample input:

5 100

Sample output:

280


Data range and tips

For $ 40 \% $ data, to ensure that the answer is less than $ 10 ^ 7 $
for another $ 20 \% $ data, to ensure that the answer is less than $ 7 \ Times 10 ^ 7 $
for another $ 20 \% $ data, $ B = 2 $
to $ 100 \% $ data, $ K \ leqslant 10 ^ 7 , B \ leqslant 15 $, 10 $ ensure the answer is less than $ ^ {18}


answer

Let me talk about the practice on the exam.

In fact, very violent, do a queue, only the initial $ 1 $ each enumerator from the quality, the number of all queue are multiplied it can be.

The last row of a sequence, looking for the first $ K $ large enough, expected to be $ 80 $ points, card good time (not all swept into the $ 10 ^ {18} $, otherwise $ TLE $) just fine.

Besides positive solution found small $ B $, $ B $ with pointers like.

Time complexity: $ \ Theta (B \ times K) $.

Expectations score: $ 100 $ points.

Actual score: $ 100 $ points.


Code time

#include<bits/stdc++.h>
using namespace std;
int B,K,fail[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
you pri [] = {} 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47;
long long s[10000001];
int main ()
{
	scanf("%d%d",&B,&K);
	s[1]=1;
	for(int i=2;i<=K;i++)
	{
		long long flag=0x3f3f3f3f3f3f3f3f;
		for(int j=0;j<B;j++)
		{
			if(s[fail[j]]*pri[j]==s[i-1])fail[j]++;
			if(s[fail[j]]*pri[j]<flag)flag=s[fail[j]]*pri[j];
		}
		s[i]=flag;
	}
	printf("%lld",s[K]);
	return 0;
}

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11736719.html