joxj simulation game September 3, 2019

joxj simulation game September 3, 2019

Title game Source: 2018qbxt Hefei Day1

The least common multiple T1

The meaning of problems: Known positive integer n, and the least common multiple of n - 246 913 578, the result of the modulo 1234567890

Data range:. 1 <= n-<10 = 100000

A lcm = a * b / gcd (a, b) (mod 1234567890)

We found great divisor modulo need, considering multiplicative inverse, but b, 1234567890 necessarily coprime, and therefore can not be used multiplicative inverse

However, due to the nature of gcd, gcd (a, b) = gcd (a% b, b), is also found that the modulus of the multiple b,

Therefore, the modulo being read directly with high precision can be at a: gcd (a, b) = gcd (a% 1234567890, b)

(However, when the examination did not think so much, guess solved directly with the conclusion, too strict a)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
ll mol;
ll gcd(ll a, ll b)
{
    return (b == 0)? a : gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
    return ((a * b)  / gcd(a,b)) % mol;
}
char ch[100100];
int main()
{
    mol = 1234567890;
    ll n = 0, m = 246913578; scanf("%s",ch + 1);
    ll len = strlen(ch + 1); ll rest = 0;
    ll alen = len; ll x = 1e9;
    while(len > 8)
    {
        ll now = 0;
        for(int i = alen - len + 1; i <= alen - len + 8; i++)
        {
            now = now * 10 + ch[i] - '0';
        }
        rest = (now + ((rest * x)% mol)) % mol;
        len -= 8;
    }
    for(int i = alen - len + 1; i <= alen; i++)
    {
        n = n * 10 + (ch[i] - '0');
    }
    n = n % mol;
    n = ((rest * x) % mol + n) % mol;
    printf("%lld\n", lcm(n, m));
    return 0;
}

T2 irreversible

This question also has the Los Valley: topic Link

The meaning of problems: 1 to find the number n satisfies the arrangement is arranged to fluctuation, the answer modulo m.

Data range:. 1 <= n-<= 1000 m <= 10 . 9

This question is to see and feel at first glance with LCIS bit like solving a sequence of waves, but soon found a big difference, this question is only one sequence, and wave sequence that question is two sequences. I started thinking that hit the table, take a look at this question there is no formula, but looking for a long or did not find the law, so I thought for a moment, this question may be found Road dp, but I think for a long time or I did not expect the special nature of this question for dp, so called violent search of trouble.

Sure enough, all the equations are difficult to write dp and the nature of the topic is related to the nature of this question as follows:

1. For a normal sequence, that the sequence can be discretized into 1 to n are arranged.

The degree of "fluctuation" 2 sequence is one of the parameters used when the sequence number described properties.

When considering the arrangement 1 to n, the maximum number of positions may be considered to represent the degree of "fluctuation" sequence.

We also found, for the first drop of the sequence and then decreased sequence, each number can be one of a sequence x into n + 1-x to swap the two sequences.

So, we need only count the number one sequence in which the program can then * 2.

When calculating F [i], i enumerator position j, j the sequence into two portions, the program calculates the number of the position, due to the nature 1, we only need to multiply selected first number of the number of the left (left composition selected from which determines the number, the number of which is selected from the right is also determined), then with C (i-1, j-1) * f [j-1] * f [ij] to.

For space arrays dynamically optimized may be employed.

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m;
long long C[1010][1010]={},f[1010]={};
int main()
{
    scanf("%d%d", &n, &m);
    C[0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        C[i][0] = 1;
        for(int j = 1; j <= i; j++)
        {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % m;
        }
    }
    f[0] = 1; f[1] = 1;
    for(int i = 2; i <= n; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            if(j&1) f[i] = (f[i] + (((f[j - 1] % m) * (f[i - j] % m)) % m) * C[i - 1][j - 1]) % m;
        }
    }
    printf("%d\n",f[n] * 2 % m);
    return 0;
}

Numerical differentiation

意题: , f 0 = , f (X) , f I = 0 , f I = , f I-1 - , f I-1

Input of the first behavior n, m n number of second behavior f (i), the output of F m , the result of the modulo 100007

Data range:. 1 <= n-<= 1000. 1 <= m <= 10 . 9 0 <= F [I] <100007

This question is Pascal's Triangle I found during the examination, but no time to do, but also did not expect to count the number of combinations with Pascal's Triangle.

First, we suspect the presence of the array such that a F m = a [0] * F [I-0] + a [. 1] * F [I-. 1] + ... + a [-I. 1] * F [I- ( i-1)]

- (1) find = A J so before this * C (m, j), the question is, when n> m how do we find when n> m is the current number of hours affect only the first m number, number initial value 0 directly to the number of combinations can be multiplied, and does not affect the answers, so we only need to go to minimum n and m can.

This question is also a pit 100007 is not a prime number, it can not be used Lucas theorem, only use extension Lucas Theorem

We will numerator and denominator the number of combinations of decomposition of the quality factor (this step is also a lot of details), then you can calculate directly.

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define mol 100007
#define ll long long
int n, m;
ll C[1010];
int fac[1010]={};
ll f[1010];
ll rest = 1;
void dvd(int x,int k)
{
    for(int i = 2; i <= n; i++)//
    {
        while(x % i == 0)
        {
            fac[i] += k; x /= i;
        }
    }
    if(x != 1)rest = (rest * (x % mol)) % mol;//
}
ll quickpow(ll a, int b)
{
    ll ret = 1;
    while(b != 0)
    {
        if(b&1) ret = ret * a % mol;
        a = a * a % mol;
        b >>= 1;
    }
    return ret;
}
int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)scanf("%lld", &f[i]);
    C[0] = 1;
    for(int i = 1; i <= min(m, n); i++)
    {
        C[i] = 1;
        dvd(m - i + 1, 1); dvd(i, -1);
        C[i] = C[i] * rest % mol;
        for(ll j = 2; j <= n; j++)
        {
            if(fac[j] != 0)
            {
                C[i] = (C[i] * quickpow(j, fac[j])) % mol;
            }
        }
        //printf("C[%d] = %d\n", i, C[i]);
        //for(int i = 1; i <= min(m, n); i++)printf("fac[%d] = %d\n", i, fac[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        ll ans = 0;
        for(int j = 0; j < i; j++)
        {
            if(j&1)
            ans = ((ans + (f[i - j] * C[j]) % mol * (-1)) % mol + mol) % mol;
            else
            ans = (ans + (f[i - j] * C[j]) % mol) % mol;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/Akaina/p/11455761.html