hdu 5750——Dertouzos(简单)
来源:互联网 发布:unity3d 手游源码 编辑:程序博客网 时间:2024/06/07 09:39
Problem Description
A positive proper divisor is a positive divisor of a number nn, excluding nn itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
Peter has two positive integers nn and dd. He would like to know the number of integers below nn whose maximum positive proper divisor is dd.
题目大意:正整数x称为n的positive proper divisor, 当且仅当x | n并且1≤ x 且n>x。 例如, 1, 2, 和3是6的positive proper divisor, 但是6不是
Peter给你两个正整数n和d. 他想要知道有多少小于n的整数, 满足他们的最大positive proper divisor恰好是d.
题解:对于每个整数,它乘以的数必须都小于等于它的最小因数,这样才能保证其满足条件。
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int maxn = 100000 + 130;const int maxm = 1e5+120;int prime[maxn];bool vis[maxm]; int mind[maxn];int n,d,cnt;void get_prime(int n){ memset(vis,0,sizeof(vis)); memset(mind,0,sizeof(mind)); vis[1]=1;cnt=0; for(int i=2;i * i<n;i++){ if(vis[i]) continue; else mind[i] = i; for(int j=i*i;j<n;j+=i){ vis[j]= 1; if(!mind[j]) mind[j]=i; } } for(int i=2;i<n;i++) if(!vis[i]) prime[++cnt]=i;}int main(){ int kase;scanf("%d",&kase); get_prime(maxm-10); while(kase--){ scanf("%d%d",&n,&d); if(d>=n) {printf("0\n");continue;} int ans = 0 ; int maxnum = min(d,(n-1)/d); for(int i=1;i<=cnt;i++){ if(prime[i]*d>=n) break; ans++; if(d%prime[i]==0) break; } printf("%d\n",ans); } return 0;}
0 0
- hdu 5750——Dertouzos(简单)
- HDU 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论)
- hdu 5750 Dertouzos(数论:质数枚举)
- HDU 5750 Dertouzos(思路题)
- HDU 5750 Dertouzos
- hdu 5750 Dertouzos
- HDU-5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos
- Hdu 5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos
- HDU 5750 Dertouzos(数论)
- HDU 5750 Dertouzos (数论)
- HDU 5750 Dertouzos
- hdu-5750-Dertouzos-数学
- HDU 5750 Dertouzos
- HDU 1711 Number Sequence(kmp专题)
- HDU 5547 Sudoku(暴力)
- python 学习(五) While 循环语句
- Android Developer Document——APP开发深度好文
- 字符串加解密 算法
- hdu 5750——Dertouzos(简单)
- 理解矩阵乘法
- next_permutation函数
- 导航栏的相关设置
- solr在酒店列表查询中的使用
- 深度学习笔记整理
- Android基础知识复习
- Git使用笔记
- android studio for android learning (二十二 )如何在camera2中加载其它控件和当前摄像头视图显示在一起以及UI优化