Problem 1607 Greedy division

http://acm.fzu.edu.cn/problem.php?pid=1607

Accept: 402    Submit: 1463
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

Oaiei has inherited a large sum of wealth recently; this treasure has n pieces of golden coins. Unfortunately, oaiei can not own this wealth alone, and he must divide this wealth into m parts (m>1). He can only get one of the m parts and the m parts have equal coins. Oaiei is not happy for only getting one part of the wealth. He would like to know there are how many ways he can divide the wealth into m parts and he wants as many golden coins as possible. This is your question, can you help him?

Input

There are multiply tests, and that will be 500000. For each test, the first line is a positive integer N(2 <= N <= 1000000), N indicates the total number of golden coins in the wealth.

Output

For each test, you should output two integer X and Y, X is the number of ways he can divide the wealth into m parts where m is large than one, Y is the number of golden coins that he can get from the wealth.

Sample Input

5 6 8

Sample Output

1 1 3 3 3 4

Hint

There are huge tests, so you should refine your algorithm.

Source

FOJ月赛-2008年5月

根据数论公式:

 /*
题意:一个人,想知道财产的分法有多少种,(财产必须平方的前提)
他想分得越多越好。
求出N M。
用欧拉的模板稍微改变一下。
N,容易解决。
M的求解不是
if(M&1) M=1;
else M=N/2;
显然15的时候是 5
实际上就是 num=max{ N/(枚举每个素因子) }
再加一个判断 if(num==N) num=1; */ #include<stdio.h>
#include<stdlib.h> int Num_Euler(int n,int *m)
{
int num=,k,i;
for(i=;i*i<=n;i++)
if(n%i==)
{
k=;
while(n%i==)
{
if(n/i>*m)
*m=n/i;
k++;
n=n/i;
}
num=num*k;
}
if(n!=)
{
num=num*;
if(n>*m)
*m=n;
}
return num;
} int main()
{
int n,k,m;
while(scanf("%d",&n)>)
{
m=-;
k=Num_Euler(n,&m);
if(m==n) m=;//加的判断,当n是一个素数的时候,在Num_Euler(n,&m)最后就会得到m==n 但是题目要求至少分成2份啊,所以为1
printf("%d %d\n",k-,m);//K-1个,不包含自己.
}
return ;
}

FUzhou 1607 Greedy division---因子个数问题。的更多相关文章

  1. FOJ 1607 Greedy division 数学题

    题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607 给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数.思路:就是求n的因子数.先将每个数 ...

  2. LightOj1028 - Trailing Zeroes (I)---求因子个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...

  3. POJ 2992 求组合数的因子个数

    求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...

  4. Divisors_组合数因子个数

    Description Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- ...

  5. POJ 2992 Divisors (求因子个数)

    题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...

  6. HDOJ(HDU) 2521 反素数(因子个数~)

    Problem Description 反素数就是满足对于任意i(0< i < x),都有g(i) < g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[ ...

  7. Easy Number Challenge(暴力,求因子个数)

    Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  8. Acdream1084 寒假安排 求n!中v因子个数

    题目链接:pid=1084">点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 ...

  9. CodeForces 546D Soldier and Number Game 打表(求质因子个数)

    题目:戳我这个题与HDUOJ 5317有异曲同工之妙 题意:题意看懂了上面的一大串英文之后其实很简单,就是给你一个正整数n,问你n有多少个质因子,不过这里n是通过a!/b!给定的,也就是说n=(a!/ ...

随机推荐

  1. 【新题】ocp 062 2019年考试新题-3

    3.A database is open read write and the instance has multiple sessions some of which have active tra ...

  2. Python os.path.join() 进行路径拼接

    在python 项目开发过程中,经常需要将获取到的路径进行拼接, # os.path.join(path1,path2) 将两个路径拼接起来 os.path.join("/usr" ...

  3. Linux core 文件 gdb

    http://blog.csdn.net/mr_chenping/article/details/13767609 在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时 ...

  4. centos6安装最新syslog-ng推送hdfs

    可参考以下网址: installhttps://www.syslog-ng.com/community/b/blog/posts/latest-syslog-ng-available-rhel-6-c ...

  5. php7 改为从栈上分配内在的思路

    php7的特点是规则上不从堆上分配内存,改为从栈上分配内存, 因为有些场景是从堆上分配内在后,还要手动释放内存,利用栈分配内在快的特点,在有需要的时候,再在堆上分配内在 但是栈上分配的内存,不能返回, ...

  6. 【OpenCV3】threshold()函数详解

    threshold()函数源码 double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxva ...

  7. node开发环境配置

    node开发环境配置 用处 NodeJS——后台 JavaScript-前台 后台其他语言 1.PHP 2.Java 3.Pythonnode优势 1.性能高 nodejs php 86 1s 1分半 ...

  8. Backing Up and Restoring HBase Data

    There are two strategies for backing up HBase:1> Backing it up with a full cluster shutdown2> ...

  9. sublime text ubuntu

    { "color_scheme": "Packages/User/SublimeLinter/Dawn (SL).tmTheme", "font_fa ...

  10. EF 一对一、一对多、多对多配置语句小记

    数据库实体间的关系无非有这么几种:一对一.一对多.多对多,这些关系在EF框架中分别有不同的创建方式: 1.在"Database First"模式中,这些关系通过SQL语句的方式建立 ...