Created
July 29, 2016 02:13
-
-
Save McSinyx/c8ec5579ee14f60f052901dd3b9ed321 to your computer and use it in GitHub Desktop.
CIRCENUM - Số vòng
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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