Pagini recente » Cod sursa (job #2317523) | Cod sursa (job #1121908) | Cod sursa (job #1803839) | Cod sursa (job #229023) | Cod sursa (job #2772658)
#include <iostream>
#include <chrono>
#include <fstream>
#include <vector>
#include <string>
int process(int i) {
static std::vector<int> cache(111);
if (cache[i] != 0) {
return cache[i];
}
int final = i;
for (int j = 1; j < i; ++j) {
final *= i;
final %= 10;
if (final == 0) {
break;
}
}
cache[i] = final;
return final;
}
void cifra() {
std::ifstream f1;
std::ofstream f2;
f1.open("../cifra.in");
f2.open("../cifra.out");
int number_of_numbers;
f1 >> number_of_numbers;
std::vector<int> precompute(111);
for (int i = 1; i < 111; ++i) {
for (int j = 1; j <= i; ++j) {
precompute[i] += process(j);
}
precompute[i] = precompute[i] % 10;
}
for (int i = 0; i < number_of_numbers; ++i) {
std::string actual;
f1 >> actual;
int nr = actual.back() - '0';
if (actual.size() > 1) {
nr += 10 * (actual[actual.size() - 2] - '0');
}
f2 << precompute[nr] << '\n';
}
}
int main() {
auto start = std::chrono::high_resolution_clock::now();
cifra();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
std::cout << std::endl << "[time]:" << duration.count() << std::endl;
return 0;
}