1022. 可被 K 整除的最小整数

 显示英文描述

 
  • 用户通过次数74
  • 用户尝试次数262
  • 通过次数75
  • 提交次数1115
  • 题目难度Medium

给定正整数 K,你需要找出可以被 K 整除的、仅包含数字 1 的最小正整数 N。

返回 N 的长度。如果不存在这样的 N,就返回 -1

示例 1:

输入:1
输出:1
解释:最小的答案是 N = 1,其长度为 1。

示例 2:

输入:2
输出:-1
解释:不存在可被 2 整除的正整数 N 。

示例 3:

输入:3
输出:3
解释:最小的答案是 N = 111,其长度为 3。

提示:

  • 1 <= K <= 10^5

 

class Solution {
public:
int smallestRepunitDivByK(int K) {
set<int> s;
int c = ;
int prod = %K;
while(!s.count(prod)) { //没有碰到过
if(prod == ) {
return c;
}
s.insert(prod);
prod = (prod*+)%K; //这也能用mo来算。。
cout << prod << " ";
++c;
}
return -;
}
};

——学到了

Leetcode 1022. 可被 K 整除的最小整数的更多相关文章

  1. [Swift]LeetCode1015. 可被 K 整除的最小整数 | Smallest Integer Divisible by K

    Given a positive integer K, you need find the smallest positive integer N such that N is divisible b ...

  2. 【LeetCode】974. 和可被 K 整除的子数组

    974. 和可被 K 整除的子数组 知识点:数组:前缀和: 题目描述 给定一个整数数组 A,返回其中元素之和可被 K 整除的(连续.非空)子数组的数目. 示例 输入:A = [4,5,0,-2,-3, ...

  3. [Swift]LeetCode974. 和可被 K 整除的子数组 | Subarray Sums Divisible by K

    Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum ...

  4. 乘风破浪:LeetCode真题_023_Merge k Sorted Lists

    乘风破浪:LeetCode真题_023_Merge k Sorted Lists 一.前言 上次我们学过了合并两个链表,这次我们要合并N个链表要怎么做呢,最先想到的就是转换成2个链表合并的问题,然后解 ...

  5. LeetCode:移除K位数字【402】

    LeetCode:移除K位数字[402] 题目描述 给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小. 注意: num 的长度小于 10002 且 ≥ k. nu ...

  6. 【LeetCode】402. Remove K Digits 解题报告(Python)

    [LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  7. 【LeetCode】373. Find K Pairs with Smallest Sums 解题报告(Python)

    [LeetCode]373. Find K Pairs with Smallest Sums 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/p ...

  8. 【LeetCode】692. Top K Frequent Words 解题报告(Python)

    [LeetCode]692. Top K Frequent Words 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/top ...

  9. 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵

    题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...

随机推荐

  1. Unity3D学习笔记(三十七):顶点偏移和溶解

    顶点偏移 沿向量方向偏移,沿自身坐标系方向偏移 沿法线方向偏移,球体放大,立方体拆分 Shader "Lesson/VFVertOffsetVertex" { Properties ...

  2. Codeforces 808G Anthem of Berland(KMP+基础DP)

    题意 给定一个字符串 \(s\) ,一个字符串 \(t\) ,其中 \(s\) 包含小写字母和 "?" ,\(t\) 只包含小写字母,现在把 \(s\) 中的问号替换成任意的小写字 ...

  3. template render in javascript

    art-template for github 中文官方文档

  4. Nuget CsvHelper 的使用

    CsvHelper:nuget地址 csv导出类||生成类 public class CSVHeader { public string head1 { get; set; } public stri ...

  5. Spring项目JUnit测试报错ClassNotFoundException解决

    Eclipse项目上有红色感叹号,各包显示正常.用JUnit测试部分能运行,部分报错,报错如下: Class not found UserTestjava.lang.ClassNotFoundExce ...

  6. JS实现ul,li排序效果

    <!DOCTYPE html> <html> <head> <title>js列表排序</title> <meta charset=& ...

  7. bean之间的属性是怎么维护的

    spring对象[bean]之间的属性是通过什么维护的: 1.构造方法:标签:constructor-arg 2.set方法:标签:property <beans xmlns="htt ...

  8. 清华镜像方法更新python包

    来自:Jinlong_Xu cmd环境下执行: conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk ...

  9. Java的CountDownLatch和CyclicBarrier的理解和区别

    CountDownLatch和CyclicBarrier的功能看起来很相似,不易区分,有一种谜之的神秘.本文将通过通俗的例子并结合代码讲解两者的使用方法和区别. CountDownLatch和Cycl ...

  10. try....fail....catch...Assert 模式的测试, fail是Junit中的功能

    try { // 反射读取properties文件 new BufferedReader(new FileReader(myConfigPath[4])); //上面没有抛出异常就是执行fail, / ...