poj 1426 Find The Multiple ( BFS+同余模定理)
Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 18390 | Accepted: 7445 | Special Judge |
Description
digits.
Input
Output
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
同余模定理:
(a*b)%n = (a%n *b%n)%n;
(a+b)%n = (a%n +b%n)%n;
枚举前14个数字为:1 、10 、11、100、101、110、111、1000、1001、1010、1011、1100、1101、1110。
。。
1110%6=(110*10+0)%6=((110%6)*10)%6+(0%6);
mod[x]=(mod[x/2]*10+x%2)%n;
#include<stdio.h>
#define N 600000
int mod[N];
int ans[200];
int main()
{
int i,k,n;
while(scanf("%d",&n),n)
{
mod[1]=1%n;
for(i=2;mod[i-1]!=0;i++)
{
mod[i]=(mod[i/2]*10+i%2)%n;
}
i--;
k=0;
while(i)
{
ans[k++]=i%2;
i/=2;
}
for(i=k-1;i>=0;i--)
printf("%d",ans[i]);
puts("");
}
return 0;
}
poj 1426 Find The Multiple ( BFS+同余模定理)的更多相关文章
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- poj 1426 Find The Multiple (bfs 搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18012 Accepted: 729 ...
- POJ 1426 Find The Multiple BFS
没什么好说的 从1开始进行广搜,因为只能包涵0和1,所以下一次需要搜索的值为next=now*10 和 next=now*10+1,每次判断一下就可以了,但是我一直不太明白我的代码为什么C++提交会错 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- POJ 1426 Find The Multiple && 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21436 Accepted: 877 ...
随机推荐
- Mathematics-基础:1+2+3+……+n
设Sn=1+2+3+……+n-1+n则有Sn=n+n-1+……+3+2+1两式相加得2Sn=(n+1)+(n+1)+……+(n+1)2Sn=n×(n+1)Sn=n×(n+1)/2
- js 简单制作键盘模拟
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head& ...
- 数论基础之组合数&计数问题
一.组合数:问题引入:现在有 n 个球,取其中的 k 个球,问一共有多少种方式?答案: 公式直观解释:我们考虑有顺序地取出 k 个球:第一次有 n 种选择,第二次有 n-1 种选择,...,第 k 次 ...
- Activiti流程定义部署方式
1 bpmn png方式部署 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); /**部署流程定义(从cl ...
- LeetCode 304. Range Sum Query 2D – Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- tomcat——大致简介和执行过程
jsp简介 JSP: JAVA Server Page 使用JAVA语言编写的一种在服务器运行的动态页面 JSP = JAVA + HTML JSP 的执行过程 1: 翻译阶段 把JSP源文件翻译成 ...
- luogu2468 [SDOI2010]粟粟的书架
二合一-- #include <iostream> #include <cstdio> using namespace std; int r, c, m, a[205][205 ...
- mysql异常Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'region_name'
Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'region_name' insert语句加的该字段有汉字,乱码造成的 解 ...
- Go map基础
package main import "fmt" //Map //创建:make(map[string]int) //获取元素: m[key] //key不存在时,获得value ...
- DP在字符匹配上的实现
在此保存下近段时间做的DP在字符匹配上的实现的题目 对于不同的字符串来说,2者只能不断将下标往后推移来实现匹配从而得到的最大匹配数 如 abcd 和 dcba 这个最大匹配数只能为1,因为两个d匹配后 ...