【数论,水题】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 main()
 8 {
 9     int n, p[maxn];
10     while(~scanf("%d", &n))
11     {
12         if(!n) {printf("0\n"); continue;}
13         int len = log10(n)+1;
14         int val = 0, x;
15         for(x = 0; x < len; x++)
16         {
17             val = val*10 + 1;
18         }
19         int res = 0;
20         if(val/n == 0)
21         {
22             val = val*10+1;
23             x++;
24         }
25         res = val%n;
26         while(res)
27         {
28             res = res*10+1;
29             res = res%n;
30             x++;
31         }
32         printf("%d\n", x);
33     }
34     return 0;
35 }

时间: 2024-10-21 10:04:40

【数论,水题】UVa 10127 - Ones的相关文章

BZOJ1968: [Ahoi2005]COMMON 约数研究(数论 水题)

Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input 3 Sample Output 5 Solve: 数论水题,求因数又不是质因数,所以,只要求出对于[1 , n]有多少个倍数,就表示[1 , n]中以i为因数的是哪些,加起来就可以了 Code: 1 #include <bits/stdc++.h> 2 using namespace std;

HDU 2674 N!Again (数论-水题)

N!Again Problem Description WhereIsHeroFrom:             Zty, what are you doing ? Zty:                                     I want to calculate N!...... WhereIsHeroFrom:             So easy! How big N is ? Zty:                                    1 <=

HDU 4143 A Simple Problem(数论-水题)

A Simple Problem Problem Description For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2. Input The first line is an integer T, which is the the number of cases. Then T line

HDU 3215 The first place of 2^n (数论-水题)

The first place of 2^n Problem Description LMY and YY are mathematics and number theory lovers. They like to find and solve interesting mathematic problems together. One day LMY calculates 2n one by one, n=0, 1, 2,- and writes the results on a sheet

洛谷数论{水题}集合

1. P1327数列排序 题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格式: 第一行,正整数n (n<=100,000). 以下若干行,一共n个数,用空格分隔开,表示数列{an},任意-231<ai<231. 输出格式: 只有一行,包含一个数,表示最少的交换次数. 输入输出样例 输入样例#1: 8 8 23 4 16 77 -5 53 100 输出样例#1: 5

hdu 1141 Factstone Benchmark 数论水题,,阶乘用斯特林公式

Factstone Benchmark Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1760    Accepted Submission(s): 973 Problem Description Amtel has announced that it will release a 128-bit computer chip by

hdu 2674 N!Again 数论水题啊~~~

N!Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3803    Accepted Submission(s): 2036 Problem Description WhereIsHeroFrom:             Zty, what are you doing ? Zty:                     

UVa 1586 Molar mass --- 水题

UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现一个从字符型的数到整型的数的转换函数,再将输入的串从头到尾扫描,遇到字母,则进一步扫描后面的数字的区间, 再调用函数进行转换,再乘以其的原子质量,最后累加到sum中即可. /* UVa 1586 Molar mass --- 水题 */ #include <cstdio> #include <

UVa 272 Tex Quotes --- 水题

题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endi