求解递推

2023-09-11 05:54:38 作者:Yoke(羁绊)

我给 F(0)= X F(I)=(A⋅F(I-1)^ 2 + B ⋅F(I-1)+ C)%百万1≤i≤N

现在给 N A B C X ,如何有效地找到所有 N 元素?

Now given N,A,B,C and X, how to find all N elements effectively?

我需要划分在2台这N个元素,其中最大的元素进去第一组,第二大在第二组,第三大在第1套等等...,并在年底需要找到总和的绝对差异性两者的集合的元素

I need to divide these N elements in 2 sets where largest element goes in 1st set ,2nd largest in 2nd set , 3rd largest in 1st set and so on...and at the end need to find absolute differnece of the sum of elements of both the sets.

我能找到这种差异不计算所有元素作为N可以大到 10 ^ 7 A B C X 是高达在最高100

Can i find this difference without computing all elements as N can be as large as 10^7 and A,B,C,X are upto at max 100.

推荐答案

请注意,该序列的下一元素仅依赖于previous之一,并且没有比M =百万不同元素的更多,因为每个结果是取模1000000的整数。因此该序列是从某点周期性的。可以产生第一少数元素(不超过M),直到找到期,然后立即知道有多少每个元素有,如果元件的总数是N

Note that the next element of the sequence depends only on the previous one, and there are no more than M=1000000 different elements since each result is an integer taken modulo 1000000. Thus the sequence is periodic from some point. You can generate the first few elements (no more than M) until you find the period, and then immediately know how many of each element there are if the total number of elements is N.

现在,相对于10 ^ 7 10 ^ 6是至少一些改进。一旦你知道每个数字从0到999999多少次发生在序列中,你可以找到在澳必需的差异(M)操作了。

Now, 10^6 is at least some improvement when compared to 10^7. And once you know for each number from 0 to 999999 how many times it occurs in the sequence, you can find the required difference in O(M) operations, too.

相关推荐