[POI2002][HAOI2007]反素数
生活随笔
收集整理的這篇文章主要介紹了
[POI2002][HAOI2007]反素数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
https://www.lydsy.com/JudgeOnline/problem.php?id=1053
https://www.luogu.org/problemnew/show/P1463
定義:
對(duì)于任何正整數(shù)x,其約數(shù)的個(gè)數(shù)記作g(x)。例如g(1)=1、g(6)=4。
如果某個(gè)正整數(shù)x滿足:g(x)>g(i) 0<i<x,則稱x為反質(zhì)數(shù)。
題解:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long n; int p[20]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,51}; long long maxn=-1,num=-1;//num是因子最大時(shí)小于n的最大數(shù),maxn是最大因子數(shù) void get(long long m,int f,int t,int pr) { //f為當(dāng)前質(zhì)數(shù)的編號(hào) ,當(dāng)前指數(shù)<pr//t為當(dāng)前約數(shù)的個(gè)數(shù) if(t>maxn||(t==maxn&&m<num))//更新最優(yōu)解num=m,maxn=t;for(int i=1;i<=pr;i++){//j表示的是當(dāng)前正在搜索的指數(shù)if(n/m<p[f])break;//若不滿足條件就跳出循環(huán)(i表示的是當(dāng)前的m)m*=p[f];if(m<=n) get(m,f+1,t*(i+1),i); //若i(即當(dāng)前的m)在區(qū)間[1,n]內(nèi)就繼續(xù)搜索。} } int main() {cin>>n;get(1,1,1,30);cout<<num<<endl; }?
總結(jié)
以上是生活随笔為你收集整理的[POI2002][HAOI2007]反素数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Ehab and the Expecte
- 下一篇: 离散数学实验题目-图