博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FUzhou 1607 Greedy division---因子个数问题。
阅读量:7038 次
发布时间:2019-06-28

本文共 2183 字,大约阅读时间需要 7 分钟。

Problem 1607 Greedy division

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月

根据数论公式:

 

1 /* 2 题意:一个人,想知道财产的分法有多少种,(财产必须平方的前提) 3       他想分得越多越好。 4       求出N M。 5 用欧拉的模板稍微改变一下。 6 N,容易解决。 7 M的求解不是 8 if(M&1) M=1; 9 else M=N/2;10 显然15的时候是 511 实际上就是 num=max{  N/(枚举每个素因子) }12 再加一个判断 if(num==N) num=1;13 14 */15 16 #include
17 #include
18 19 int Num_Euler(int n,int *m)20 {21 int num=1,k,i;22 for(i=2;i*i<=n;i++)23 if(n%i==0)24 {25 k=1;26 while(n%i==0)27 {28 if(n/i>*m)29 *m=n/i;30 k++;31 n=n/i;32 }33 num=num*k;34 }35 if(n!=1)36 {37 num=num*2;38 if(n>*m)39 *m=n;40 }41 return num;42 }43 44 int main()45 {46 int n,k,m;47 while(scanf("%d",&n)>0)48 {49 m=-1;50 k=Num_Euler(n,&m);51 if(m==n) m=1;//加的判断,当n是一个素数的时候,在Num_Euler(n,&m)最后就会得到m==n 但是题目要求至少分成2份啊,所以为152 printf("%d %d\n",k-1,m);//K-1个,不包含自己.53 }54 return 0;55 }

 

 

转载于:https://www.cnblogs.com/tom987690183/p/3249870.html

你可能感兴趣的文章
ajax 同步和异步的区别
查看>>
linux shell单引号、双引号及无引号区别(考试题答案系列)--看到这篇文章之后我豁然开朗...
查看>>
排错 zabbix-agent 主机重启无法被监控
查看>>
win10操作系统
查看>>
Mutual Funds引起的一桩桩血案
查看>>
zabbix如何监控nginx性能
查看>>
python3的异常处理
查看>>
linux C 动态共享库编译链接
查看>>
用jdbcTempate调用存储过程,处理BLOBCLOB小记
查看>>
oracle study road
查看>>
《你必须知道的495个C语言问题》笔记
查看>>
数据中心可靠级别划分
查看>>
你真的理解什么是“财富自由”吗?
查看>>
释放LINUX内存(请使用火狐浏览器浏览本页面)
查看>>
Andrew Ng 深度学习笔记-01-week3-课程
查看>>
Android获取通过XML设置的空间的高宽
查看>>
生活的苦逼
查看>>
在iptables防火墙下开启vsftpd的端口
查看>>
Mysql、MariaDB 新型主从集群配置GTID
查看>>
Linux HA Cluster的实例演示(2)
查看>>