主要是打表---数豆子

打表可以简单理解为把需要算的结果先都算出来存进数组里

多次需要调用结果就可以直接从表里找

 

 

Problem G:

Count beans will be crazy

Time Limit: 1 Sec Memory Limit: 128 MB

Description

Mother bought a basket of beans before winter came. Cleaning the beans, she

fou

nd a bean left when she counted them two by two; there're two beans left when

she counted them three by three; there're three beans left when she counted them

four by four; there're four beans left when she counted them five by five...and

there're n

-

1 bean

s left when she counted them n by n. Now do you know how many

beans there are in the basket at least?

Input

Input n (2<=n<=40 ).

Process to end of file.

Output

Output how many beans there are in the basket at least?

Sample Input

6

Sample Output

59

 

 

 

 

 

 

 

 

#include<stdio.h>

#include<iostream>

using namespace std;

//long long func1(long long a,long long b);

int main()

{

    long long ans[45]={0,0,2,6,12,60,60,420,840,2520,2520,27720,27720,360360,360360,360360,720720,12252240,12252240,232792560,232792560,232792560,232792560,5354228880,5354228880,26771144400,26771144400,80313433200,80313433200,2329089562800,2329089562800,72201776446800,144403552893600,144403552893600,144403552893600,144403552893600,144403552893600,5342931457063200,5342931457063200,5342931457063200,5342931457063200};

 

    /*ans[2]=2;

    for(int i=3;i<=40;i++)

    {

        ans[i]=ans[i-1]*(i/func1(i,ans[i-1]));

        cout<<ans[i]<<',';

    }*/

    int n;

    cin>>n;

    cout<<ans[n]-1<<endl;

    //printf("%lld",ans[n]-1);

    return 0;

}

/*long long func1(long long a,long long b)

{

    while(1)

    {

        if(a<b)

        {

            long long t=a;

            a=b;

            b=t;

        }

        if(a%b==0)

            return b;

        a=a%b;

    }

}*/

 

 

题意:n个n个拿豆子 最后剩n-1个 求最少有多少豆子

找最大公约数然后求最小公倍数在-1

 

 

 

 

注意多组输入

 

#include<stdio.h>

#include<iostream>

using namespace std;

int main()

{

    long long ans[45]={0,0,2,6,12,60,60,420,840,2520,2520,27720,27720,360360,360360,360360,720720,12252240,12252240,232792560,232792560,232792560,232792560,5354228880,5354228880,26771144400,26771144400,80313433200,80313433200,2329089562800,2329089562800,72201776446800,144403552893600,144403552893600,144403552893600,144403552893600,144403552893600,5342931457063200,5342931457063200,5342931457063200,5342931457063200};

    int n;

    while(~scanf("%d",&n))

    printf("%I64d",ans[n]-1);

    return 0;

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值