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

【题意】

让你把一个字符串分成左右两个部分
形成两个正数
使得这两个正数一个能被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. Linux查找和替换目录下所有文件中字符串(转载)

    转自:http://rubyer.me/blog/1613/ 单个文件中查找替换很简单,就不说了.文件夹下所有文件中字符串的查找替换就要记忆了,最近部署几十台linux服务器,记录下总结. 查找文件夹 ...

  2. bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】

    二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...

  3. composer查看安装情况

    composer install --no-progress --profile -vvv

  4. MongoDB一些常用指令与他的JavaScript的对应表

  5. 234 Palindrome Linked List 回文链表

    请检查一个链表是否为回文链表. 进阶:你能在 O(n) 的时间和 O(1) 的额外空间中做到吗? 详见:https://leetcode.com/problems/palindrome-linked- ...

  6. javascript 信息的发布与删除

    现在很多类似以微博发布动态的效果,下面为一个用 JavaScript写的小小的类似微博发布信息的案例 <!DOCTYPE html> <html lang="en" ...

  7. LN : leetcode 207 Course Schedule

    lc 207 Course Schedule 207 Course Schedule There are a total of n courses you have to take, labeled ...

  8. struts2之通配符映射

    系统有n多个请求时候,不可能以一个action对应一个映射.可以用通配符映射将成百上千请求简化成一个通用映射. 通配符映射规则:1.若找到多个匹配,没有通配符的将胜出. 2.若指定的动作不存在,str ...

  9. jstree -- 使用JSON 数据组装成树

    概述: 前面主要是html数据,这里主要是json数组 1.格式 jsTree需要一个具体格式JSON数据,在标准的语法没有那个字段是必须的-而是那些是你需要的.请记住你可以获取任何你请求的其他属性, ...

  10. MySQL的基本概念与操作

    数据库的基本概念什么是数据库?用于存储和管理数据的仓库.数据库的特点:持久化存储数据的.其实数据库就是一个文件系统方便存储和管理数据使用了统一的方式操作数据库 – SQL数据库的分类:数据库根据存储采 ...