fzuoj1607Greedy division

题目链接:

点我点我

题目:

 Problem 1607 Greedy division

Accept: 436    Submit: 1590

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

568

 Sample Output

1 13 33 4

 Hint

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

 Source

FOJ月赛-2008年5月

思路:

这个题目首先预处理,其实这个题目就是在求有多少个因数,所以可以用素数打表的思路,因为每次扫描到的j,一定是i的倍数,故a[j]++,例如是24,则i到2,3,4,6,8,12,24时都会加一次。。。然后就是如果是素数,则直接输出1和1.相当于一种优化吧。。

代码为:

#include<cstdio>
#include<cstring>
const int maxn=1000000+10;
int a[maxn];
int main()
{
    int n,i;
    memset(a,0,sizeof(a));
    for(int i=2;i<=maxn;i++)
        for(int j=i;j<=maxn;j=j+i)
            a[j]++;
    while(~scanf("%d",&n))
    {
        if(a[n]==1)
            printf("%d %d\n",1,1);
        else
            {
                for(i=2;i<=maxn/2;i++)
                    if(n%i==0)
                     break;
                printf("%d %d\n",a[n],n/i);
            }

    }
    return 0;
}

fzuoj1607Greedy division,布布扣,bubuko.com

时间: 2024-08-29 07:48:11

fzuoj1607Greedy division的相关文章

light oj 1214 - Large Division

1214 - Large Division   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if

HDU 3480 Division(斜率优化+二维DP)

Division Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 999999/400000 K (Java/Others) Total Submission(s): 3984    Accepted Submission(s): 1527 Problem Description Little D is really interested in the theorem of sets recently. There’s a pro

uva725 Division

题目描述: abcde / fghij =N a,b···j 为0-9任意一个数,且互相不同 任意给一个n(2<=n<=79),输出满足条件的可能 思路1:10!只有不到400w,直接暴力枚举即可 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int a[]= {1,0,2,3,4,5,6,7,8

BZOJ 1385: [Baltic2000]Division expression

题目 1385: [Baltic2000]Division expression Time Limit: 5 Sec  Memory Limit: 64 MB Description 除法表达式有如下的形式: X1/X2/X3.../Xk 其中Xi是正整数且Xi<=1000000000(1<=i<=k,K<=10000) 除法表达式应当按照从左到右的顺序求,例如表达式1/2/1/2的值为1/4.但可以在表达式中国入括号来改变计算顺序,例如(1/2)/(1/2)的值为1.现给出一个除

bzoj1385: [Baltic2000]Division expression

欧几里得算法.可以发现规律,a[2]作为分母,其他作为分子,必定是最好的选择.判断是否为整数即可. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) int read(){ int x=0;char c=getchar(); whil

Codeforces-808D Array Division 【multiset】

Description Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements

UVa 725 Division --- 简单枚举

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666 /* UVa 725 Division --- 简单枚举 */ #include <cstdio> #include <cstring> bool used[10]; /* 判断传进来的两个数是否满足条件 */ bool judge(int a, i

uva 725 Division(除法)暴力法!

uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that t

[LeetCode] Multiplication Withtout Division

Question: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. Solve it without division operator and in O(n). For example Output[0] w