spojAE00(递推+找因子)

Rectangles

Byteman has a collection of N squares with side 1. How many different rectangles can he form using these squares?
Two rectangles are considered different if none of them can be rotated and moved to obtain the second one. During rectangle construction, Byteman can neither deform the squares nor put any squares upon any other ones.
Input
The first and only line of the standard input contains one integer N (1 <= N <= 10000).
Output
The first and only line of the standard output should contain a single integer equal to the number of different rectangles that Byteman can form using his squares.
Example
For the input data:
6
the correct result is:
8
用≤n个小正方形能拼成多少个矩形??事实证明暴力能AC
我用的递推,注意遍历2到sqrt(n)找因子,否则会RE,注意数据范围,否则也会RE。。

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,a[10020],b,i,j,k;
    scanf("%d",&n);
    a[1]=1;
    for(i=2; i<=n; i++)
    {
        b=1;
        for(j=2;j<=sqrt(i); j++)
        {
            if(i%j==0)
                b++;
        }
        a[i]=a[i-1]+b;
    }
    cout<<a[n]<<'\n';
    return 0;
}

全部评论

相关推荐

hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务