Skip to content

Instantly share code, notes, and snippets.

@McSinyx
Created July 29, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McSinyx/c8ec5579ee14f60f052901dd3b9ed321 to your computer and use it in GitHub Desktop.
Save McSinyx/c8ec5579ee14f60f052901dd3b9ed321 to your computer and use it in GitHub Desktop.
CIRCENUM - Số vòng
/*
* CIRCENUM - Số vòng <http://laptrinh.ntu.edu.vn/Problem/Details/5548>
*
* Copyright (C) 2016 Raphael McSinyx
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
const long long INTPOW10[] = {1, 10, 100, 1000, 10000, 100000, 1000000,
10000000, 100000000, 1000000000, 10000000000,
100000000000, 1000000000000, 10000000000000,
100000000000000, 1000000000000000,
10000000000000000, 100000000000000000,
1000000000000000000};
char intlog10(long long n)
{
char val = 0;
while (n > 9) {
n /= 10;
val++;
}
return val;
}
char isnt_circle(long long n)
{
return n % 10 != n / INTPOW10[intlog10(n)];
}
int main()
{
long long l, r;
scanf("%lld %lld", &l, &r);
while (isnt_circle(l))
l++;
while (isnt_circle(r))
r--;
char llog = intlog10(l);
char rlog = intlog10(r);
long long l0, r0, val = 0;
for (char i = llog; i <= rlog; i++) {
l0 = INTPOW10[i] + 1;
l0 = (l0 > l) ? l0 : l;
r0 = INTPOW10[i + 1] - 1;
r0 = (r0 < r) ? r0 : r;
r0 -= l0;
if (r0 >= 0) {
val++;
val += (r0 < 10) ? r0 : (r0 / 10);
}
}
printf("%lld\n", val);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment