Sunday, September 28, 2014

UVa - 113 - Power of Cryptography

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int n, mod, get, root, temp, m;
    vector <int> ans;
    string pran;
    while(cin >> n >> pran){
        get = n*n, mod = 0, m = 0;
        int l = pran.size();
        for(int i = 0; i < l; i++){
            temp = (mod * 10) + (pran[i]-48);
            mod = ((mod * 10) + (pran[i]-48)) % n;
            if(m == 1 && temp < get)ans.push_back(0);
            if(temp >= get){
                root = temp / get;ans.push_back(root);
                m = 1;
            }
        }
        for(int i = 0; i < ans.size(); i++)cout << ans[i];cout << endl;
        ans.clear();
    }
    return 0;
}

No comments:

Post a Comment