poj 2551 Ones(同余)
来源:互联网 发布:郑州冰川网络 编辑:程序博客网 时间:2024/06/02 21:35
Ones
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11459 Accepted: 6487
Description
Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?
Input
Each line contains a number n.
Output
Output the number of digits.
Sample Input
3 7 9901
Sample Output
3612题意:求n的一个倍数都由1组成,并且输出最小的这个倍数的位数
思路:利用同余定理,边加1边取模即可,第一个模为0即是答案
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;int main(){ int n; while(~scanf("%d",&n)) { int sum=0; for(int i=1;i<=n;i++) { sum=(sum*10+1)%n; if(!sum) { printf("%d\n",i); break; } } } return 0;}
0 0
- poj 2551 Ones(同余)
- NYoj410how many ones?(同余定理)
- POJ 3844(同余)
- zoj 1889 ones (同余定理)
- poj 1061(线性同余方程。。。。)
- POJ-1465(同余+高精度)
- POJ 2115(线性同余方程)
- poj-2635(同余模运算)
- POJ 2635(同余定理)
- POJ 1426 (BFS + 同余定理)
- poj 2769 同余
- POJ 2551 Ones(数论)
- poj 2115 同余方程
- poj 2891 同余方程
- POJ 1006 同余方程组
- POJ 2115 同余方程
- POJ 1061 同余方程
- poj 1426 Find The Multiple (bfs+同余定理)
- 滑雪(线性dp)
- Java中的线程
- Spring配置多个PropertyPlaceholderConfigurer
- 完整版Jad+Eclipse plugins
- 转载:要嫁就嫁程序猿——钱多话少死的早
- poj 2551 Ones(同余)
- Spring事务配置总结
- Python-环境创建-pip安装&rzsz安装
- 从源码解析HashMap与HashTable的不同
- CAShapeLayer 属性(strokeStart和strokeEnd)
- 一种排序
- chess(博弈,SG,多校)
- Yii2-使用afterLogin和beforLogin自动更新上次登录时间
- CXF异常:No operation was found with the name