29782023-02-06 19:01:42CWMSorozat generáláscpp11Hibás válasz 25/5017ms34732 KiB
// SorozatGen.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int GenNextElement(int Base, int A, int B, int M) {
    Base = Base * A + B;
    Base %= (int)pow(10, M*3);
    Base /= (int)pow(10, M);
    return Base;
}

signed main()
{
    int M, BeginningNum, A, B, Lenght, K;
    cin >> M >> BeginningNum >> A >> B >> Lenght >> K;
    K = Lenght - K;
    vector<int> LastElementMet((int)pow(10, M*2));
    int Looplenght = 0;
    int NumbersBeforeLoopLenght = 0;
    int OG = BeginningNum;
    int OGL = Lenght;
    for (size_t i = 1; i < (int)pow(10, M*2); i++)
    {
        BeginningNum = GenNextElement(BeginningNum, A, B, M);
        if (LastElementMet[BeginningNum] == 0) {
            LastElementMet[BeginningNum] = i;
        }
        else {
            NumbersBeforeLoopLenght = LastElementMet[BeginningNum];
            Looplenght = i - LastElementMet[BeginningNum];
            break;
        }
        /*cout << BeginningNum << "\n";*/
    }
    cout << BeginningNum << "\n";
    vector<int> Loop;
    for (size_t i = 0; i < Looplenght; i++)
    {
        Loop.push_back(BeginningNum);
        BeginningNum = GenNextElement(BeginningNum, A, B, M);
    }
    vector<int> CountTillLenght((int)pow(10, M*2));
    BeginningNum = OG;
    for (size_t i = 0; i < NumbersBeforeLoopLenght-1; i++)
    {
        BeginningNum = GenNextElement(BeginningNum, A, B, M);
        CountTillLenght[BeginningNum]++;
    }
    Lenght -= NumbersBeforeLoopLenght;
    int Repeated = Lenght % Looplenght;
    for (size_t i = 0; i <= Repeated; i++)
    {
        CountTillLenght[Loop[i]]++;
    }
    Lenght -= Repeated;
    int smallloop = Lenght / Looplenght;
    for (size_t i = 0; i < Looplenght; i++)
    {
        CountTillLenght[Loop[i]] += smallloop;
    }
    int CCount = 0;
    for (size_t i = 0; i < CountTillLenght.size(); i++)
    {
        CCount += CountTillLenght[i];
        if (CCount >= K+1) {
            cout << i << "\n";
            return 0;
        }
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base25/50
1Elfogadva0/03ms1808 KiB
2Hibás válasz0/017ms33172 KiB
3Részben helyes1/23ms2088 KiB
4Részben helyes1/23ms2216 KiB
5Részben helyes1/23ms2432 KiB
6Részben helyes1/23ms2676 KiB
7Részben helyes1/22ms2720 KiB
8Részben helyes2/43ms3008 KiB
9Részben helyes2/43ms3140 KiB
10Részben helyes2/43ms3220 KiB
11Részben helyes2/43ms3308 KiB
12Részben helyes2/43ms3524 KiB
13Részben helyes2/414ms34388 KiB
14Részben helyes2/417ms34340 KiB
15Részben helyes2/417ms34620 KiB
16Részben helyes2/417ms34540 KiB
17Részben helyes2/416ms34732 KiB