CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Katajisto
Submission time:2017-10-06 20:17:21 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int calc(uint64_t)':
input/code.cpp:23:47: error: 'pow' was not declared in this scope
  arvot /= pow(10,(numerot - 1) - (i % numerot));
                                               ^
input/code.cpp:11:15: warning: unused variable 'tens' [-Wunused-variable]
  unsigned int tens;
               ^

Code

#include <stdint.h>
#include <iostream>
#include <vector>
using namespace std;
int calc(uint64_t i)
{
	uint64_t     numerot = 1U;
	uint64_t     arvot = 1U;
	uint64_t     raja = 9U;
	unsigned int tens;
	i--;
	while (i / raja >= numerot) {
		const uint64_t vanha_raja = raja;
		i -= numerot * raja;
		numerot++;
		arvot *= 10U;
		raja *= 10U;
		if (raja <= vanha_raja)
			break;
	}
	arvot += i / numerot;
	arvot /= pow(10,(numerot - 1) - (i % numerot));
	return arvot % 10U;
}
int main()
{
	vector<long long> queryvector = {};
	long long int query;
	cin >> query;
	for (long int i = 0; i < query; i++)
	{
		long long int q;
		cin >> q;
		queryvector.push_back(q);
	}
	for (long long kysely : queryvector)
	{
		cout << calc(kysely) << endl;
	}
}