hdu 5109(构造数+对取模的理解程度)
Alexandra and A*B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 802 Accepted Submission(s): 211
has a little brother. He is new to programming. One day he is solving
the following problem: Given two positive integers A and B, output A*B.
This
problem is even easier than the last one. Alexandra can't wait to give
him another task: Given a positive integer A and a string S(S only
contains numbers.), find the minimum positive integer B, such that S is a
substring of T, where T is the decimal notation of A*B.
See the sample for better understanding.
Note: S can contain leading zeros, but T can't.
A≤10,000,1≤|S|≤8.
To C++ programmers: if you want to output 64-bit integers, please use "%I64d" specifier or cout.
96 19
2 0086
1 1
2
5043
1
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
LL a;
char s[];
while(scanf("%lld%s",&a,s)!=EOF){
int len = strlen(s);
if(strcmp(s,"")==){
printf("0\n");
continue;
}
LL ls = ,mid=;
for(int i=;i<len;i++) ls*=;
for(int i=;i<len;i++){
mid = mid*+s[i]-'';
}
LL ans = -;
for(LL i=;i<=;i*=){
for(LL j=(s[]=='');j<a;j++){
LL t = (j*ls+mid)*i;
LL y = (a-t%a)%a;
if(y>=i) continue;
if(ans<) ans = t+y;
else ans = min(t+y,ans);
}
}
printf("%I64d\n",ans/a);
}
return ;
}
hdu 5109(构造数+对取模的理解程度)的更多相关文章
- hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值
pog loves szh II Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4704 Sum 超大数幂取模
很容易得出答案就是2^(n-1) 但是N暴大,所以不可以直接用幂取模,因为除法操作至少O(len)了,总时间会达到O(len*log(N)) 显然爆的一塌糊涂 套用FZU1759的模板+顺手写一个大数 ...
- W - Doom HDU - 5239 线段树 找取模的规律+求一个很大的数的平方对一个数取模的写法 特别的模数==2^63-2^31
这个题目一开始感觉还是有点难的,这个模数这么大,根本就不知道怎么写,然后去搜了题解,知道了怎么去求当x很大的时候x的平方对一个数取模怎么样不会爆掉. 然后还顺便发现了一个规律就是当一个数更新一定次数之 ...
- HDU 1212 大整数的取模运算
因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...
- C#取模的理解:为什么当a<b,a%b=a?
一,取模a%b 1,如果a>b,例如10%7=3,这是什么原因呢?可以根据下面的理解 10 =7*1+3,则模就是3 2,如果a<b,例如7%10 = 7,这时怎么得到的呢?根据下面来理解 ...
- HDU 4869 (递推 组合数取模)
Problem Turn the pokers (HDU 4869) 题目大意 有m张牌,全为正面朝上.进行n次操作,每次可以将任意ai张反面,询问n次操作可能的状态数. 解题分析 记正面朝上为1,朝 ...
- ACM-较大的数乘法取模技巧*
比如模数是1e15这种,相乘的时候爆LL了,但是又不想用大数,咋办呢? long long ksc(long long a, long long b, long long mod){ ; while( ...
- POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】
一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模
D. The Child and Sequence At the children's day, the child came to Picks's house, and messed his h ...
随机推荐
- border与background定位
1.background定位的局限 只能相对于左上角数值定位,不能相对于右下 即background-position默认相对于左上方定位的 2.怎样让图片相对于右下角? background-pos ...
- Java重写与重载
重写的规则: 参数列表必须完全与被重写方法的相同: 返回类型必须完全与被重写方法的返回类型相同: 访问权限不能比父类中被重写的方法的访问权限更低.例如:如果父类的一个方法被声明为public,那么在子 ...
- hadoop进阶
Java 多线程安全机制 1.操作系统有两个容易混淆的概念,进程和线程. 进程:一个计算机程序的运行实例,包含了需要执行的指令:有自己的独立地址空间,包含程序内容和数据:不同进程的地址空间是互相隔离的 ...
- FTP使用心得
1、创建文件夹的函数,一次只能创建一层。 2、没有现成的判断文件夹是否存在的函数,如果文件夹不存在就创建,会报异常。有以下封装好的函数。可以直接调用。 1 2 3 4 5 6 7 8 9 10 11 ...
- python基础实践(三)
-*-列表是新手可直接使用的最强大的python功能之一,它融合了众多重要的编程概念.-*- # -*- coding:utf-8 -*-# Author:sweeping-monkQuestion_ ...
- python学习总结----时间模块 and 虚拟环境(了解)
time - sleep:休眠指定的秒数(可以是小数) - time:获取时间戳 # 获取时间戳(从1970-01-01 00:00:00到此刻的秒数) t = time.time() print(t ...
- [C++] 数据结构应用——链表
C++ 数据结构应用--链表 代码已经封装成class啦,方便使用. 头文件:Linklist.h #include <iostream> /*********************** ...
- LeetCode-N皇后
LeetCode-N皇后 n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. ...
- HDU 1709 母函数天平问题 可出现减法的情况 The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- ajax-高设3
ajax 1.XHR Ajax 技术的核心是 XMLHttpRequest 对象(简称 XHR),这是由微软首先引入的一个特性,其他浏览器提供商后来都提供了相同的实现.在 XHR 出现之前,Ajax ...