首页 > 其他分享 >A. k-th divisor

A. k-th divisor

时间:2024-03-08 22:01:12浏览次数:16  
标签:divisor factors long easy problem th

https://codeforces.com/problemset/problem/762/A

This is a easy problem based on number theory.
We just simply iterate i from 1 to the value of sqrt(n), and check if n is divisble by the value of i and find all of its divisors, then sort them and get the answer.

void solve(){
    long long n;
    cin >> n;

    vector<long long> factors;
    for (long long i = 1; i * i <= n; ++i){
        if (n % i == 0){
            factors.emplace_back(i);
            if (i != n / i){
                factors.emplace_back(n / i);
            }
        }
    }

    sort(factors.begin(), factors.end());
    int k;
    cin >> k;

    cout << (k > factors.size() ? -1ll : factors[k - 1]) << '\n';
}

//what a easy problem..

标签:divisor,factors,long,easy,problem,th
From: https://www.cnblogs.com/yxcblogs/p/18061941

相关文章

  • [Rust] Thread 2: Waiting all thread to finish using join handler
    Codefrompreviousblog:usestd::thread;usestd::time::Duration;fnmain(){thread::spawn(||{foriin1..10{println!("hinumber{}fromthespawnedthread!",i);thread::sleep(Duration::from_millis(1))......
  • [Rust] Intro Thread: 1. Thread with spawn
    Weuse spawntocreateanewthread:usestd::thread;usestd::time::Duration;fnmain(){thread::spawn(||{foriin1..10{println!("hinumber{}fromthespawnedthread!",i);thread::sleep(Duration::from......
  • [Maven] pom.xml报"parent.relativePath" of POM xxxxxx
    0序1问题描述springboot项目pom.xml/maven报'parent.relativePath'ofPOMcom.know-data.framework:know-data-study-springboot:1.0.0-SNAPSHOT(F:\xxx\know-data-parent\know-data-study-parent\know-data-study-springboot\pom.xml)pointsatcom.k......
  • How to use try-catch with DB::transaction in Laravel
    Howtousetry-catchwithDB::transactioninLaravel.Whenaddingnumerousqueries,DB::transaction()isusedtocheckwhethereachquerywasproperlyrunbeforerollingback.Therefore,canweuseatry-catchblockwithdb::transactionaswell?Usingat......
  • python的ansible库--ansible_runner
    介绍AnsibleRunner是ansible官方提供的一个工具和python库,当直接与Ansible进行交互或作为另一个系统的一部分与Ansible进行交互时,无论是通过容器映像接口,作为独立工具还是作为可以导入的Python模块,它都可以提供帮助。目的是为Ansible提供稳定且一致的接口抽象。参考网站[官方......
  • python 脚本中 # -*- coding: utf-8 -*-的作用
     001、[root@pc1test1]#lstest01.pytest02.py[root@pc1test1]#cattest01.py#!/usr/bin/envpython#注释内容list1=["aa","bb","cc"]print(list1)[root@pc1test1]#cattest02.py#!/usr/bin/envpython#-*-coding:utf-8......
  • python3.7.4 RV1126 交叉编译
    首先,十分感谢大佬分享的交叉编译攻略,原文链接如下:https://www.cnblogs.com/Se7eN-HOU/p/16736164.html在此基础上,本人经过一周时间的踩坑,终于在RV1126开发板上实现了交叉编译。现记录本人实际编译版本与上述版本略有不同之处。主要是由于3.5.2版本的python和openssl1.0.2g在......
  • python脚本的开头该怎么写
     001、第一句通常为a、#!/usr/bin/envpythonb、#!/usr/bin/python首先以上两脚都是指定脚本语言的解释器,均表示用python解释器执行下面的脚本。a的写法比b的写法更加的健壮。因为b把解释器写死了,如果python的可执行程序不在/usr/bin/python中,那么程序就容易出错。而a的......
  • python-memo-3
    x_1+x_2+x_3+x_4=8的正整数解(>0):从7个空隙中添加3个挡板->C(M,N),M=7,N=3m=int(input('m='))n=int(input('n='))fm=1fornuminrange(1,m+1):fm*=numfn=1fornuminrange(1,n+1):fn*=numfm_n=1fornuminrange(1,......
  • github 搭建个人导航网
    最近搭建了个个人的导航网,具体内容见下图,欢迎大家访问吖,点我访问 (首次访问较慢) 具体实现是使用vue3编写,白嫖github的page部署首先在github上创建一个仓库:name.github.io#name是你github的名字然后在本地创建一个vue3项目 然后把刚创建的仓库clone到......