我有一个编程问题,希望我检查30,000个六角形数字(由公式:H(n)= n(2n-1)给出),其中有多少可以被数字1到12整除.
我的代码如下:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int hex, count = 0;
for (int n = 1; n <= 30000; n++)
{
hex = n * ((2 * n) - 1);
if (hex % 1 == 0 && hex % 2 == 0 && hex % 3 == 0 && hex % 4 == 0 && hex % 5 == 0 && hex % 6 == 0 && hex % 7 == 0 && …Run Code Online (Sandbox Code Playgroud)