ACM练习 反素数
2015-06-06 19:47
363 查看
Problem Description
反素数就是满足对于任意i(0<i<x),都有g(i)<g(x),(g(x)是x的因子个数),则x为一个反素数。现在给你一个整数区间[a,b],请你求出该区间的x使g(x)最大。
Input
第一行输入n,接下来n行测试数据
输入包括a,b, 1<=a<=b<=5000,表示闭区间[a,b].
Output
输出为一个整数,为该区间因子最多的数.如果满足条件有多个,则输出其中最小的数.
Sample Input
Sample Output
反素数就是满足对于任意i(0<i<x),都有g(i)<g(x),(g(x)是x的因子个数),则x为一个反素数。现在给你一个整数区间[a,b],请你求出该区间的x使g(x)最大。
Input
第一行输入n,接下来n行测试数据
输入包括a,b, 1<=a<=b<=5000,表示闭区间[a,b].
Output
输出为一个整数,为该区间因子最多的数.如果满足条件有多个,则输出其中最小的数.
Sample Input
3 2 3 1 10 47 359
Sample Output
2 6 240 Hint 2的因子为:1 2 10的因子为:1 2 5 10
#include <stdio.h> #include <stdlib.h> using namespace std; int getFactor(int x); int main() { struct factor { int name; int value; }F; int n,a,b,i, x,k,c; bool IsFactor; scanf("%d", &n); while (n--) { scanf("%d%d", &a, &b); c = b-a; x=0; factor* temp = (factor*)malloc(sizeof(factor)*c); int* fac = (int*)malloc(sizeof(int)*b+1); for (i=1;i<=b;i++ ) { fac[i] = getFactor(i); } for (i=a;i<=b; i++) { IsFactor = true; for(k=a; k <i;k++) { if ( fac[i] <= fac[k]) { IsFactor = false; break; } } //printf("%d\n",IsFactor ); if (IsFactor) { temp[x].name = i; temp[x].value = fac[i]; x++; } } F.value = temp[0].value; F.name = temp[0].name; for (i =1; i< x ; i++ ) { if (temp[i].value >F.value) { F.name = temp[i].name; F.value = temp[i].value; } } printf("%d\n",F.name); } return 0; } int j,value; int getFactor(int x) { value = 0; for (j=1; j <= x; j++) { if (x%j==0) { value++; } } return value; }
相关文章推荐
- /bin/bash^M: bad interpreter: No such file or directory
- PAT复杂度_最大子列和问题、最大子列和变种
- delphi之完美Splash方案
- bzoj 3209 数位DP+欧拉定理
- VTR-to-Bitstream 1 General Recognition
- JSON-RPC轻量级远程调用协议介绍及使用
- ACDREAM 05B Circle vs Triangle(DFS专场)
- C++ 一些容易忽略的基本点
- Mac OS 安装cocoapods出现SSL connection错误
- MongoDB Windows环境安装及配置
- MongoDB Windows环境安装及配置
- Calendar 类
- Perl中常见的特殊符号
- 图片不存在时显示一个默认的图片
- Data Flow ->> Script Component
- ubuntu使用
- python字典排序
- 网页开发之Cookie生命周期
- Struts1入门
- ACM练习 A Mathematical Curiosity