#include <iostream>
#include <vector>
using namespace std;
int main()
{
int t, q, n, p_0, p_1, p_temp;
vector<int> digits;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> p_0 >> p_1 >> q >> n;
digits.push_back(p_0);
digits.push_back(p_1);
for (int i = 2; i <= (n - 1); i++)
{
p_temp = (4 * digits[i - 1] + digits[i - 2]);
digits.push_back(p_temp);
}
}
}
Witam oto treść mojego zadania:
**Problem statement is simple and straight forward . You will be given a non-negative integer P of length N and you need to check whether it's divisible by Q ?
Integer P will be given in its decimal representation with P0 as leftmost digit and P1 as second digit from left !
Rest of the digit can be generated from the formula :
Pi = ( 4*Pi-1 + Pi-2 ) modulo Q for 2 <= i <= N-1
Input
The first line contains one integer T - denoting the number of test cases.
T lines follow each containing four integers P0 , P1 , Q and N !
Output
For each testcase output YES if the corresponding integer is divisible by Q and NO otherwise.
Constraints
T <= 100000
0 < P0 , P1 , Q < 10
0 < N <= 1018
Example
Input:
4
1 4 2 2
1 4 2 1
4 2 3 2
3 4 7 3
Output:
YES
NO
YES
NO
Explanation
Value of P is 14, 1, 42, 345 in respective cases !**
Wpadlem na pomysl aby stworzyc tablice dynamiczna vector, po czym przy uzyciu wzoru obliczac poszczegolne cyfry nastepnie dodac je do tablicy, zlaczyc wszystkie cyfry w jedna liczbe i sprawdzic czy liczba jest podzielna na Q po czym wpisac wynik do tablicy z odpowiedziami. Mysle ze moj zamysł jest ok ale w praktyce gdy probuje skompilowac moj program na etapie ktory dodalem, program wyswietla blad krytyczny. Domyslam sie ze moze chodzic o ten fragment:
for (int i = 2; i <= (n - 1); i++)
{
p_temp = (4 * digits[i - 1] + digits[i - 2]);
digits.push_back(p_temp);
}
lecz nie mam pojecia dlaczego wywala blad. Czy moze mi ktos pomoc? Pozdrawiam