以下是HackerEarth挑战赛中的一个问题 -
Roy有一个大小为NxN的矩阵.行和列的编号从1到N.第i行的第j列包含整数除法i/j.
换句话说,Matrix [i] [j] = int(i/j)其中1≤i,j≤N.
Your task is to find sum of this matrix i.e.
sum = 0
for i=1 to N-1
for j=1 to N-1
sum += Matrix[i][j]
Constraints:
1 ? T ? 10
1 ? N ? 1000000
Run Code Online (Sandbox Code Playgroud)
这是我解决这个问题的方法
#include <cstdio>
#include <cassert>
using namespace std;
#define MAXT 10
#define MAXN 1000000
long long solve(long long N){
long long ans = 0;
for(int i=1;i<N-1;i++)
{
for(int j=1; j<N-1 ; j++)
{
int temp = N*i/j; …Run Code Online (Sandbox Code Playgroud) 编译时出错:
raja@raja-desktop:~/socket$ g++ Socket.cpp
Socket.cpp: In member function ‘int Socket::recv(std::string&) const’:
Socket.cpp:135: error: ‘cout’ is not a member of ‘std’
Run Code Online (Sandbox Code Playgroud)
Socket.cpp的来源:
// Implementation of the Socket class.
#include "Socket.h"
#include "string.h"
#include <string.h>
#include <errno.h>
#include <fcntl.h>
Socket::Socket() :
m_sock ( -1 )
{
memset ( &m_addr,
0,
sizeof ( m_addr ) );
}
Socket::~Socket()
{
if ( is_valid() )
::close ( m_sock );
}
bool Socket::create()
{
m_sock = socket ( AF_INET,
SOCK_STREAM,
0 );
if ( ! is_valid() …Run Code Online (Sandbox Code Playgroud)