FUzhou 1607 Greedy division---因子个数问题。
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
Sample Output
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---因子个数问题。的更多相关文章
- FOJ 1607 Greedy division 数学题
题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607 给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数.思路:就是求n的因子数.先将每个数 ...
- LightOj1028 - Trailing Zeroes (I)---求因子个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...
- POJ 2992 求组合数的因子个数
求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...
- Divisors_组合数因子个数
Description Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- ...
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
- HDOJ(HDU) 2521 反素数(因子个数~)
Problem Description 反素数就是满足对于任意i(0< i < x),都有g(i) < g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[ ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Acdream1084 寒假安排 求n!中v因子个数
题目链接:pid=1084">点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 ...
- CodeForces 546D Soldier and Number Game 打表(求质因子个数)
题目:戳我这个题与HDUOJ 5317有异曲同工之妙 题意:题意看懂了上面的一大串英文之后其实很简单,就是给你一个正整数n,问你n有多少个质因子,不过这里n是通过a!/b!给定的,也就是说n=(a!/ ...
随机推荐
- Linux下安装python虚拟环境(virtualenv,vritulaenvwrapper)
一.virtualenv virtualenv是如何创建"独立"的Python运行环境的呢? 原理很简单,就是把系统Python复制一份到virtualenv的环境,用命令sour ...
- Android的基础知识
一.adb 的简单命令 1. adb devices : 连接当前手机的设备 2.adb kill-server : 杀死当前的adbmingling 3.adb start-server : ...
- sublime-text-how-to-jump-to-file-from-find-results-using-keyboard
http://209.116.186.231/#newwindow=1&q=sublime+text+find+results+jump http://stackoverflow.com/qu ...
- PHP中日期函数
1,转化为时间戳函数:strtotime() 本函数接受一个包含美国英语日期格式的字符串并尝试将其解析为Unix时间戳,其值相对于now参数给出的时间,如果没有提供此参数则使用系统当前时间. < ...
- [Swift实际操作]七、常见概念-(6)日期Date和DateFormatter日期的格式化
本文将为你演示日期类型的使用,以及如何对日期进行格式化. 首先引入需要使用到的界面框架 import UIKit 初始化一个日期对象,它的值和当前电脑中的日期相同 var date = Date() ...
- 《JAVA与模式》之适配器模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述适配器(Adapter)模式的: 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能 ...
- Java并发(二)-实现同步
并发带来的问题 先看一个单例类,后文中都会用到: public class SimpleWorkingHardSingleton { private static SimpleWorkingHardS ...
- (转)windows 2003 远程桌面关闭 运行程序退出解决
windows 2003 远程桌面关闭 运行程序退出解决 原文:http://2798996.blog.51cto.com/2788996/503365 情况:远程桌面到2003,运行一个程序,然后关 ...
- 如何修复“sshd error: could not load host key”
问题:当我尝试SSH到一台远程服务器时,SSH客户端登陆失败并提示“Connection closed by X.X.X.X”.在SSH服务器那端,我看到这样的错误消息:“sshd error: co ...
- PHP 如何 安全配置
配置选项 phpinfo( ) 函数可用于php.ini文件的定位 A.1. allow_url_fopen 选项允许你如同本地文件一样引用远程资源: 我推荐关闭allow_url_fopen选项,除 ...