×

contest

# PREREQUISITES:

Basic Mathematics, Modular-arithematic

# Problem:

Given a base K and number M and a String. We have to convert this string moving from left to right and output the result at every step which contains the modulus M of decimal representation of the substring encountered till now.

# Explanation:

Starting from left, to find the value at current index, multiply the value at previous index by the given base and add the value at current index in a given string to it an take modulus M at every step.

#include <iostream.h>
#include <string.h>
using namespace std;
int t , k , m , temp;
char str[10001];

int main(int argc, char const *argv[])
{
scanf("%d" , &t);
while(t--) {
scanf("%d %d" , &k , &m);
scanf("%s" , str);
int len = strlen(str);
temp = 0;
for (int i = 0; i < len; ++i)
{
temp = ( (temp*k)%m + (int)(str[i]-'0') ) %m;
printf("%d ", temp);
}
printf("\n");
}
return 0;
}

This question is marked "community wiki".

6★guruji
113
accept rate: 0%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,682
×342
×139

question asked: 11 May '15, 23:37

question was seen: 679 times

last updated: 13 May '15, 19:59