UVa 10127 - Ones

题目:求一个全是1组成的最小可以整除n的数。

分析:数论,模拟。每次保留mod n的余数乘以10加1即可。

说明:每天一水题。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	while (cin >> n) {
		int value = 1,count = 1;
		while (value%n) {
			value = value%n*10+1;
			count ++;
		}
		printf("%d\n",count);
	}
	return 0;
}
时间: 2024-08-15 17:40:53

UVa 10127 - Ones的相关文章

uva 10127 - Ones(数论)

题目链接:uva 10127 - Ones 题目大意:给出n,问说者少要多少为1才可以整除n. 解题思路:等于是高精度取模,直到余数为0为止. #include <cstdio> #include <cstring> int main () { int n; while (scanf("%d", &n) == 1) { int ans = 1, c = 1; while (c) { c = (c * 10 + 1) % n; ans++; } print

(imcomplete) UVa 10127 Ones

方法:暴力 数论 其实我们可以先证明一下为什么n(不被2和5整除)的一个倍数可以在十进制下被表示成1111111...111, 即证明存在一个形如1111...111的数可以被n整除.n 不能被2和5整除,可以得出 n 和 10 是 互质的(comprime),那么10 mod n 存在一个multiplicative order (https://en.wikipedia.org/wiki/Multiplicative_order).然后我们设11111111...111 (ordn(10)

【数论,水题】UVa 10127 - Ones

题目链接 题意:给你一个数n,问最少有多少个1构成的“1”串(1,11,...)能整除n; 比如:111能被3整除: 111111能被7整除:... 作为水货觉得只要自己能1A的都是水题=. = 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cmath> 5 using namespace std; 6 const int maxn = 10010; 7 int

UVA 10127题目描述

Given any integer 0 ≤ n ≤ 10000 not divisibleby 2 or 5, some multiple of n is a number whichin decimal notation is a sequence of 1’s. Howmany digits are in the smallest such a multipleof n?InputA ?le of integers at one integer per line.OutputEach out

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B