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. spring JdbcTemplate批量插入以及单个插入时获取id

    1. 批量更新插入 jdbcTemplate.batchUpdate(String sql, List<Object[]> batchArgs) Object[]数组的长度为每条记录的参数 ...

  2. 匹配img标签的正则表达式

    $preg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';//匹配img标签的正则表达式 preg_match_all($ ...

  3. Jmeter做并发测试(设置集合点)

    集合点:让所有请求在不满足条件的时候处于等待状态. 如:我集合点设置为50,那么不满足50个请求的时候,这些请求都会集合在一起,处于等待状态,当达到50的时候,就一起执行.从而达到并发的效果. 那么J ...

  4. WPF一步步开发XMPP IM客户端2:主窗体设计

    UI设计方案: 在设计窗体UI之前,先要了解一些主要的接口和帮助类: 对于主窗的左侧列表,容器内的Item必须实现ILeftItem的接口,比如联系人.系统消息.群等,接口包含点击事件 public ...

  5. JS:函数柯里化

    函数柯里化 柯里化 在计算机科学中,柯里化(Currying)是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术. 简单来说,就 ...

  6. Swift 4.0 废弃的柯里化

    // 柯里化 // http://www.jianshu.com/p/6eaacadafa1a                               Swift 2.0 柯里化方法 (废弃) / ...

  7. apache2.4配置weblogic12c集群(linux环境)

    首先确定环境已装apache2.4,没装的话可以看下这篇文章apache2.4一键脚本安装(linux环境) 1.下载apache分发模块mod_wl_24.so 下载apache2.4的weblog ...

  8. 使用Jacob操作Wrod文档的工具类代码

    一.需要有jacob的jar包支持 import java.util.Iterator; import java.util.List; import java.util.HashMap; import ...

  9. 记一次Socket编程踩的坑

    闲来无事研究了下Socket,想用它做个简单的聊天室模型,结果踩了个坑,整半天才出来,惭愧啊,先上完成的代码吧 服务端: public partial class Form1 : Form { pub ...

  10. html学习笔记(一)

    认识网页 网页组成 由文字.图片.输入框.视频.音频.超链接等组成. web标准 W3C组织(万维网联盟) Html (结构标准 ),相当人的身体. Css 样式(表现)标准 , 相当与给人化妆 变的 ...