私は最初の要素3
と次の要素、すなわち、v[i] = (v[i - 1] * v[i - 1]/(i + 2) + v[i - 1] * i + i + 1) % 666013
の後に構築された要素で配列のnth
の番号を探しています。ここで、v
が配列です。私のコードは機能していると思いますが、次の問題があります。 n = 7
については最初にy = 600198
、次のステップではy = 3755353636
であるが、その段階ではy
が360237639204
であると予想した。なぜそれが起こるのですか?私はWindows 7の究極のx64でVisual Studio 2017を使用しています。x * xが正しく計算されないのはなぜですか?
#define _CRT_SECURE_NO_DEPRECATE
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
int main()
{
FILE *input;
if ((input = fopen("C:\\Users\\HP\\Documents\\Visual Studio 2017\\Projects\\ConsoleApplication2\\hex.in", "r")) == NULL)
{
perror("Error opening hex.in\n");
return 1;
}
FILE *output;
if ((output = fopen("hex.out", "w+")) == NULL)
{
perror("Error opening hex.out\n");
return 1;
}
int n;
fscanf_s(input, "%d", &n);
int i = 1;
unsigned long x = 3;
unsigned long y = 8;
bool found = false;
while(!found)
{
if (i == n)
{
found = true;
fprintf(output, "%d", x);
}
i++;
x = y;
y = x * x;//for i = 7 I expect y to be 360237639204 after this step
y /= (i + 2);
y += x * i;
y += i + 1;
y %= 666013;
}
fclose(input);
fclose(output);
return 0;
}
try 'unsigned long long'、32ビットはその値を保持しません – sp2danny