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;
}

全部评论

相关推荐

06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务