You are not logged in. Please login at www.codechef.com to post your questions!

×

Digvijay vs Supriya - EDITORIAL

PROBLEM LINK:

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".

asked 11 May '15, 23:37

guruji's gravatar image

6★guruji
113
accept rate: 0%

edited 13 May '15, 19:59

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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