cf490 C. Hacking Cypher(无语)

http://codeforces.com/contest/490/problem/C

表示我考场上犯逗。。

这个拆成霍纳边乘边mod即可。。

为毛我考场胡思乱想?

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,(a),sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }

const int N=1e6+5;
char s[N];
bool ok[N];
int n;
long long a, b;

int main() {
	scanf("%s", s+1);
	n=strlen(s+1);
	read(a); read(b);
	int pos=-1;
	ll k=0, p=1;
	for3(i, n, 1) {
		k=(k+(ll)(s[i]-'0')*p)%b;
		p=(p*10)%b;
		if(s[i]-'0'==0) continue;
		if(k==0) ok[i]=1;
	}
	k=0;
	for1(i, 1, n-1) {
		k=(k*10+s[i]-'0')%a;
		if(k==0 && ok[i+1]==1) {
			pos=i;
			break;
		}
	}
	if(pos==-1) { puts("NO"); return 0; }
	puts("YES");
	for1(i, 1, pos) putchar(s[i]); puts("");
	for1(i, pos+1, n) putchar(s[i]);
	return 0;
}

  

posted @ 2014-11-24 06:25  iwtwiioi  阅读(331)  评论(0编辑  收藏  举报