1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Kuglarz.cpp : main project file.

//#include "stdafx.h"
#include <iostream>
#include <list>
#include <queue>
#include <vector>
#include <functional>
#include <set>
#include <map>
#include <string>

using namespace std;

#define maxCups 2001

priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > availableChecks;
list < pair<long long, set<int>*> >** buckets;
long long k,a,b;


//void revealBucket(int bucket) {
//	for (list < pair<long long, set<int>*> >::iterator it = buckets[bucket]->begin(); it != buckets[bucket]->end(); ++it)
//	{
//		pair<int, set<int>*> p = *it;
//		p.second->erase(bucket);
//		if (p.second->size() == 1) {
//			availableChecks.push(make_pair(p.first, *(p.second->begin())));
//		}
//	}
//}


int main()
{

	ios_base::sync_with_stdio(0);

	cin >> k >> a >> b;
	map<int, int> powermap;

	for (int i = 0; i <= 9; i++) 
	{
		powermap.insert(pair<int,int>(i, i*i));
	}

	long long potential_number = k;
	while (potential_number <= a)
	{
		potential_number += k;
	}

	long long solutions = 0;


	while (potential_number <= b)
	{
		long long tmpNumber = potential_number;
		int max_length = to_string(b).length();
		vector<int> numbers(max_length);

		while (tmpNumber != 0) 
		{
			numbers.insert(numbers.begin(), tmpNumber % 10);
			tmpNumber = tmpNumber / 10;
		}
		

		long long tmpSolution = 0;

		std::vector<int>::iterator it;
		for (it = numbers.begin(); it< numbers.end(); it++)
		{
			int number = *it;
			tmpSolution += powermap.at(number);
		}
		
		tmpSolution *= k;
		if (tmpSolution == potential_number) {
			solutions++;
		}

		potential_number += k;
	}

	cout << solutions;

	//long long** costs;
	//long long** bestRouteCosts;
	//long long** newBestCost;
	//long long** oldBestCost;
	//costs = new long long*[cupsNumber];
	//bestRouteCosts = new long long*[cupsNumber];
	//newBestCost = new long long*[cupsNumber];
	//oldBestCost = new long long*[cupsNumber];

	////buckets = new list < pair<long long, set<int>*> >*[cupsNumber];
	//int totalCost = 0;

	//for (int i = 0; i < cupsNumber; i++) {
	//	costs[i] = new long long[cupsNumber];
	//	bestRouteCosts[i] = new long long[cupsNumber];
	//	newBestCost[i] = new long long[cupsNumber];
	//	oldBestCost[i] = new long long[cupsNumber];
	//	//buckets[i] = new list<pair<long long, set<int>*> >;
	//}

	//for (int i = 0; i < cupsNumber; i++) {
	//	for (int j = 0; j < cupsNumber - i; j++) {
	//		cin >> costs[i][j];
	//		newBestCost[i][j] = LLONG_MAX;
	//		oldBestCost[i][j] = LLONG_MAX;
	//	}
	//}

	//// inicjalizacja poczatkowych dostepnych sprawdzen
	////for (int i = 0; i < cupsNumber; i++) {
	//// pair<int,int> p (costs[i][0], i);
	//// availableChecks.push(p);
	////}

	//for (int i = 0; i < cupsNumber; i++) {
	//	bestRouteCosts[i][0] = costs[i][0];
	//}


	//for (int length = 2; length <= cupsNumber; length++) {
	//	for (int left = 0; left < cupsNumber - length + 1; left++) {
	//		int right = left + length - 1;
	//		long long bestPrice = LLONG_MAX;
	//		long long initialPrice = costs[left][right - left];
	//		for (int k = left; k <= right; k++) {
	//			long long leftPrice = 0;
	//			long long rightPrice = 0;
	//			//Lewy
	//			if (k > left) {
	//				leftPrice = bestRouteCosts[left][(k - 1) - left];
	//			}

	//			//Prawy
	//			if (k < right) {
	//				rightPrice = bestRouteCosts[k + 1][right - (k + 1)];
	//			}

	//			long long tmpPrice = leftPrice + rightPrice + initialPrice;
	//			if (tmpPrice < bestPrice) {
	//				bestPrice = tmpPrice;
	//			}
	//		}

	//		bestRouteCosts[left][right - left] = bestPrice;
	//	}
	//}

	//for (int i = 0; i < cupsNumber; i++) {
	// for (int j = 0; j < cupsNumber - i; j++) {
	//  for (int k = i; k < i + j; k++) {
	//   if (bestCost[k] > costs[i][j])
	//	   cin >> costs[i][j];
	//  }
	// }
	//}


	//for (int i = 0; i < cupsNumber; i++) {
	// for (int j = 1; j < cupsNumber - i; j++) {
	//  set<int>* requiredBuckets = new set<int>;
	//  for (int k = i; k <= i + j; k++) {
	//   requiredBuckets->insert(k);
	//  }
	//  pair<int, set<int>*> p = make_pair(costs[i][j], requiredBuckets);

	//  for (int k = i; k <= i + j; k++) {
	//   (*buckets[k]).push_back(p);
	//  }
	// }
	//}

	//for (int i = 0; i < cupsNumber; i++) {
	// cout << "Bucket " << i << " possibilities:" << endl;
	// for each (pair<int, set<int>> p in *buckets[i])
	// {
	//  cout << p.first << endl;
	// }
	//}

	//for (int i = 0; i < cupsNumber; i++) {
	//	for (int j = 0; j < cupsNumber - i; j++) {
	//		cout << bestRouteCosts[i][j] << " ";
	//	}
	//	cout << endl;
	//}

	//bestCost[0] = 0;
	//for (int i = 0; i <= cupsNumber; i++) {
	// for (int j = 0; j < cupsNumber - i; j++) {
	//  long long cost;
	//  cost = bestCost[i] + bestRouteCosts[i][j];
	//  if (bestCost[i + j + 1] > cost)
	//   bestCost[i + j + 1] = cost;
	// }
	//}

	//for (int i = 0; i < cupsNumber; i++) {
	// pair<long long, int> selectedOption = availableChecks.top();
	// availableChecks.pop();
	// totalCost += selectedOption.first;
	// //cout << "Selected cup: " << selectedOption.second << " for cost: " << selectedOption.first << endl;
	// revealBucket(selectedOption.second);
	//}

	/*cout << bestCost[cupsNumber + 1];*/
	//cout << liczba * liczba << endl;

	return 0;
}