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

全部评论

相关推荐

10-14 23:01
已编辑
中国地质大学(武汉) Java
CUG芝士圈:虽然是网上的项目,但最好还是包装一下,然后现在大部分公司都在忙校招,十月底、十一月初会好找一些。最后,boss才沟通100家,别焦虑,我去年暑假找第一段实习的时候沟通了500➕才有面试,校友加油
点赞 评论 收藏
分享
冷艳的小师弟在看机会:jd测评乱点直接被挂了,哭死~
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务