Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define io_speed ios_base::sync_with_stdio(0);cin.tie(0)
string s;
int a,b,vis[1000005];
int main(){
    io_speed;
    cin>>s;
    cin>>a>>b;
    int base=1,ans=0,len = s.size();
    memset(vis,0,sizeof(vis));
    for(int i=len-1;i>0;i--){
        ans = ( ans + (s[i] - '0')*base ) % b;
        vis[i] = ans;
        base = base*10%b;
    }
    ans=0;
    for(int i=0;i<len-1;i++){
        ans = ( ans*10 + s[i]-'0' ) % a;
        if( ans==0 && vis[i+1]==0 && s[i+1]!='0' ){
            cout<<"YES\n";
            cout<<s.substr(0,i+1)<<endl;
            cout<<s.substr(i+1,len-i-1)<<endl;
            return 0;
        }
    }
    puts("NO");
    return 0;
}

 

posted @ 2014-11-25 09:36  qscqesze  阅读(189)  评论(0编辑  收藏  举报