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!/ ...
随机推荐
- day103 跨域请求 与频率访问限制.
目录 一.跨域请求 二.频率访问限制 一 .同一个域下的ajax请求访问 url文件 from django.conf.urls import url from django.contrib imp ...
- 201621123018《Java程序设计》第2周学习报告
Week02-Java基本语法与类库 1.本周学习总结 Java数据类型分为基本数据类型和引用数据类型.布尔型是Java特有的数据类型.本周重点学习了字符串类型String,String类型中==和e ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Scapy:网络的掌控者
窃取email认证: 测试代码: #!/usr/bin/python #coding=utf-8 from scapy.all import * #数据包回调函数 def packet_callbac ...
- django 实现全局支持跨域请求
Django 实现允许跨域请求 1.安装django-cors-headers pip install django-cors-headers 2.配置settings.py文件 INSTALLED_ ...
- 克隆linux虚拟机
背景:有时候,我们在用虚拟机的时候会用到多个进行使用.重新安装会花费大量的时间,此时,我们可以通过vmware虚拟机自带的功能快速克隆出完全相同的系统. 前提:被克隆的虚拟机系统要处于关闭状态 步骤: ...
- C#4.0使用dynamic 动态添加属性
最近做一个项目,用wpf mvvm实现,而前台表格需要根据数据库某表的设置不同生成不同的列名.过去用winform和Ado.net实现这种功能的时候就只需要拼装DataTable,拼成最后需要的表格, ...
- 【LeetCode】390. 消除游戏
题目 给定一个从1 到 n 排序的整数列表. 首先,从左到右,从第一个数字开始,每隔一个数字进行删除,直到列表的末尾. 第二步,在剩下的数字中,从右到左,从倒数第一个数字开始,每隔一个数字进行删除,直 ...
- POJ 1089
#include <iostream> #include <algorithm> #define MAXN 50005 using namespace std; struct ...
- 使用Maven命令行快速创建项目骨架(archetype)
> mvn archetype:generate 接下来就会输出一些列带索引变化的archetype项可供我们选择,然后提示我们选择一个编号,可以直接回车选择默认的编号(392),然后就跟着 ...
- (转)mysql5.7 根据二进制文件mysqlbinlog恢复数据库 Linux
原文:http://blog.csdn.net/qq_15058425/article/details/61196085 1.开始mysqlbinlog日志功能 先找打my.cnf文件的位置: 2.编 ...