【链接】 我是链接,点我呀:)

【题意】

让你把一个字符串分成左右两个部分
形成两个正数
使得这两个正数一个能被a整除,一个能被b整除
找到任意一个解就可以

【题解】

枚举分割的断点i
枚举的时候用同余率算出来s[1..i]和a以及b取余的结果
怎么得到s[i+1..len-1]呢?
只要用s[1..len]-s[1..b]就可以了
乘的时候可能会爆int,小心处理

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e6;
static class Task{ String s;
long a,b;
long sumb = 0,prea = 0,preb = 0;
long aftb[] = new long[N+10]; public void solve(InputReader in,PrintWriter out) {
s = in.next();
a = in.nextInt();b = in.nextInt(); aftb[(int)s.length()] = 1%b;
for (int i = (int)s.length()-1;i>=0;i--) {
aftb[i] = aftb[i+1]*10%b;
}
for (int i = 0;i < (int)s.length();i++) {
sumb = sumb*10 + s.charAt(i)-'0';
sumb = sumb%b;
}
for (int i = 0;i < (int)s.length()-1;i++) {
prea = prea * 10 + s.charAt(i)-'0';
prea = prea%a;
preb = preb * 10 + s.charAt(i)-'0';
preb = preb%b;
long temp = (sumb-preb*aftb[i+1]%b)%b;
if (temp<0) temp+=b;
if (temp==0 && prea ==0) {
if (s.charAt(i+1)=='0') continue;
out.println("YES");
for (int j = 0;j <=i;j++) {
out.print(s.charAt(j));
}
out.println();
for (int j = i+1;j < (int)s.length();j++) {
out.print(s.charAt(j));
}
return;
}
}
out.println("NO"); }
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
}
}
}

【Codeforces 490C】Hacking Cypher的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 796C】Bank Hacking(用一些技巧来代替multiset)

    [题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...

  3. 【codeforces 796C】Bank Hacking

    [题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...

  4. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 750F】New Year and Finding Roots

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. Spring Theme简单应用

    Spring MVC特性里由一个是关于Spring Theme主题的应用,所以写了个Demo 1.这里先看项目结构(Meven项目) 2.所需的POM依赖 <dependency> < ...

  2. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会【tarjan】

    几乎是板子,求有几个size>1的scc 直接tarjan即可 #include<iostream> #include<cstdio> #include<cstri ...

  3. noip2002矩阵覆盖(搜索)

    矩阵覆盖 题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见 ...

  4. P2973 [USACO10HOL]赶小猪

    跟那个某省省选题(具体忘了)游走差不多... 把边搞到点上然后按套路Gauss即可 貌似有人说卡精度,$eps≤1e-13$,然而我$1e-12$也可以过... 代码: #include<cst ...

  5. PROTEUS快捷键与部分知识点

    缩放 有以下几种方法对原理图进行缩放: 移动鼠标需要所放的地方,滚动鼠标滑轮进行缩放. 移动师表需要缩放的地方,按键盘F6放大,F7缩小 按下ShIFT键,鼠标左键拖拽出需要放大的区域,这叫SHIFT ...

  6. Too many open files故障解决一例

    Linux环境WebSphere输出日志: [// ::: EDT] 000090b7 SystemErr R Caused by: java.io.FileNotFoundException: /o ...

  7. [ Luogu 1273 ] 有线电视网

    \(\\\) \(Description\) 一棵\(N\)个节点的树,编号在\([N-M+1,N]\)内的点必定为叶子节点,且这些点都有一个收益值\(Val_i\),同时每一条树边都有一个代价. 访 ...

  8. Android Bitmap转换WebP图片导致损坏的分析及解决方案

    背景 作为移动领域所力推的图片格式,WebP图片在商业领域证明了其应有的价值.基于其他格式的横向对比,其在压缩性能表现,及还原度极为优秀,节省大量的带宽开销.基于可观的效益比,团队早前已开始磋商将当前 ...

  9. scroll的应用

    jQuery(document).ready(function($){ $('#shang').click(function(){ $('html,body').animate({scrollTop: ...

  10. vue学习图解

    vue2.0版本的学习图解个人心得!本文为原创禁止转载!!转载需要注明出处,谢谢合作!!!