Skip to content

Instantly share code, notes, and snippets.

@Mahedi-61
Last active April 8, 2018 02:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mahedi-61/b2cee1ba6175525e923ead4717590075 to your computer and use it in GitHub Desktop.
Save Mahedi-61/b2cee1ba6175525e923ead4717590075 to your computer and use it in GitHub Desktop.
codeforces problem solution in c
// my solution to problem http://codeforces.com/problemset/problem/897/B
#include<stdio.h>
#include<math.h>
int main(){
int num_digit = 0, remainder = 0;
long int num_palindrome, count = 0, n = 0;
long long int palindrome = 0, mod = 0, rev_num = 0, arr_sum = 0;
scanf("%ld %lld", &num_palindrome, &mod);
while(num_palindrome > count){
count++;
remainder = 0;
rev_num = 0;
num_digit = 0;
n = count;
while(n != 0){
n /= 10;
num_digit++;
}
n = count;
while(n != 0){
remainder = n % 10;
rev_num = rev_num * 10 + remainder;
n /= 10;
}
palindrome = count * (int)pow(10, num_digit) + rev_num;
//printf("%lld", palindrome);
//printf(" count: %ld\n", count);
arr_sum +=palindrome;
}//end of while loop
printf("%lld", (arr_sum % mod));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment