POJ 1426 Find The Multiple(数论——中国同余定理)
题目链接:
http://poj.org/problem?id=1426
Description
Input
Output
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
题意描述:
输入n (1 <= n <= 200)
输出一个由0和1组成的数并且能够被n整除
解题思路:
看了题解有了一些思路,用mod[i]=mod[i/2]*10+i%2;这个式子计算二进制i在十进制的形式并存进mod[i]数组,所以使用long long 定义mod数组,很容易理解
#include<stdio.h>
long long mod[];
int main()
{
int n;
while(scanf("%d",&n),n)
{
int i;
for(i=; mod[i-]%n != ;i++)
mod[i]=mod[i/]*+i%;// mod[i]表示十进制形式的二进制i
printf("%I64d\n",mod[i]);
}
return ;
}
但是延伸一下,如果超过200或者更大呢,请参考
#include<stdio.h>
#define N 600000
int mod[N];
int ans[];//根据情况增大数组
int main()
{
int i,k,n,j;
while(scanf("%d",&n),n)
{
mod[]=%n;
for(i=;mod[i-]!=;i++)
mod[i]=(mod[i/]*+i%) %n;
//printf("i-1=%d\n",i-1);
i--;
k=;
while(i)
{
ans[k++]=i%;
i/=;
}
for(i=k-;i>=;i--)
printf("%d",ans[i]);
puts("\n");
}
return ;
}
POJ 1426 Find The Multiple(数论——中国同余定理)的更多相关文章
- POJ 1426 Find the Multiple 思路,线性同余,搜索 难度:2
http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+ ...
- (简单) POJ 1426 Find The Multiple,BFS+同余。
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- 广搜+打表 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 --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ 1426 Find The Multiple (dfs??!!)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
随机推荐
- eslint常见规则总结
google: eslint+rules es6: impot When you import the module's default, don't use brace {} 意思是,当你使用默认的 ...
- 字符串MD5加密运算
public static string GetMd5String(string str) { MD5 md5 = MD5.Create(); by ...
- NumPy学习笔记 一
NumPy学习笔记 一 <NumPy学习笔记>系列将记录学习NumPy过程中的动手笔记,前期的参考书是<Python数据分析基础教程 NumPy学习指南>第二版.<数学分 ...
- golang社区
a development list for Go Programming Language https://groups.google.com/forum/#!forum/golang-dev a ...
- gitlab 升级
=============================================== 2017/10/21_第1次修改 ccb_warlock = ...
- PS字体倾斜、变形
整体效果: 学习地址:http://www.wzsky.net/html/Photo/psjc/psc/125890_1.html 第一步新建画布,这个大家必须会,输入文字"基"基 ...
- ASP.NET如何通过后台数据库提供的链接播放视频(不使用外置插件)
1.后台视频数据库: 2.aspx中的关键代码: <asp:DataList ID="DataList2" runat="server" DataKeyF ...
- python中星号的意义(**字典,*列表或元组)
传递实参和定义形参(所谓实参就是调用函数时传入的参数,形参则是定义函数是定义的参数)的时候,你还可以使用两个特殊的语法:*.** . 调用函数时使用* ,** test(*args)中 * 的作用:其 ...
- popupwindow那些坑
1. new PopupWindow(vw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 如果 ...
- asp.net core webapi 服务端配置跨域
在前后端分离开发中服务端仅仅只为前端提供api接口,并且前后端往往单独部署,此时就会出现浏览器跨域问题.asp.net core提供了简单优雅的解决方案. 在startup文件的Configure添加 ...