long long int 를 선언시 에러가 발생합니다.

kldpzone의 이미지

제가 2^53승을 계산하고 싶습니다.
검색을 해보니 long long 으로 64bit int를 정의할 수 있다고 하는데 아래와 같이 짜니 에러가 나네요..

컴파일 환경은 VC++ 6.0 입니다.

#include <iostream>
#include <string>
#include <math.h>
#include <limits.h>

int main() {
	long long int num;  // 2^53 을 계산하고 싶음
	int n , j ;
	long long int limit ; // 소수를 계산하기 위한 루프중 최적의(내가 생각할때) 적은 루프수
	int i , tmp  ;

	n = 53 ;  

	num = pow( 2 , n ) - 1 ;  // 2^53 계산하기

	limit = sqrt(num) + 1 ;  // limit까지만 루프를 돌려서 소수를 찾을 수 있다.

	printf ( "Big number is %d and limitation is %d\n\n" , num , limit ) ;

	j = 2 ;
	for ( i = 2 ; i < limit ; ) {
		i = 2 * j -1 ; // limit로 루프수를 줄였지만 짝수를 빼고 홀수만 계산해서 더 빠르게 소수를 찾는다.
		j++;

		tmp = num % i ; // 나머지가 0인지 알아본다.

		if ( tmp == 0 ) {  // 나머지가 0이면 소수가 아니다
			printf ( "This number is not prime.\n" ) ;
			printf ( "It's devided by number %d\n\n" , i ) ;
			return 0;
		}
	}

	printf ( "It's prime.\n" ) ;

	printf ( "\nThis calculate %d times.\n\n" , i ) ;

//	printf ( "%d\n" , num / 2351 );

 
	return 0 ;

}

Quote:
C:\Documents and Settings\DBLAB04\My Documents\강의\algorithms\2-47.cpp(7) : error C2632: 'long' followed by 'long' is illegal
C:\Documents and Settings\DBLAB04\My Documents\강의\algorithms\2-47.cpp(9) : error C2632: 'long' followed by 'long' is illegal

그리고 double형으로 선언하면 64bit 자리를 잡는데
double형 % double형 으로 나머지를 구하면 또한 아래와 같이 에러가 납니다.

Quote:
C:\Documents and Settings\DBLAB04\My Documents\강의\algorithms\2-47.cpp(25) : error C2296: '%' : illegal, left operand has type 'double'

제가 주요하게 알고 싶은건 64bit int를 VC++ 6.0 에서 정의하는 것입니다.

cdpark의 이미지

kldpzone wrote:

제가 주요하게 알고 싶은건 64bit int를 VC++ 6.0 에서 정의하는 것입니다.

_int64 형이 Visual C++에서 정의된 64bit 정수형입니다.

하지만 이것만 쓴다고 위 코드가 돌지는 않습니다. pow 등이 _int64 형을 돌려주는 함수가 아니니깐요.

kldpzone의 이미지

그러면 처음에 선언한
long long int num;

위 코드부분은 맞는 건가요?

pow가 _int64를 return 하지 않는다면 for( ; < n ; ) 까지 하면 될듯한데..

	for ( i = 1 ; i <= n ; i ++ ) {
		num *= 2 ;
	}

이렇게 pow 부분은 바꿨습니다.

그런데 처음 변수 선언시 long long int 는 맞는 건가요?
_int64 형이 C++에서 정의가 되었다고 해도 선언은 어떻게 하나요? 계속 같은 에러가 납니다.

cdpark의 이미지

kldpzone wrote:
_int64 형이 C++에서 정의가 되었다고 해도 선언은 어떻게 하나요? 계속 같은 에러가 납니다.

_int64 num;

:roll:
익명 사용자의 이미지

__int64 입니다. underscore 2개...

yeonpil_net의 이미지

다들 답은 핀트가 나간 답을 말하시네요.

long long int 는 C99 표준에서 정의되었습니다.

visual C 6.0 버전은 나온 때가 그 때보다 이전이고, 당연히 C99 지원하지 않습니다.

!23456---1----+----2----+----3----+----4----+----5----+----6----+----7-2--+----8
"배웠다"는 "할 수 있다"의 동의어가 아니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.