首页 \ 问答 \ 进程终止,状态为-107374167(Process terminated with status -107374167)

进程终止,状态为-107374167(Process terminated with status -107374167)

我试图打印给定数字的素数因子。 我的代码适用于某些输入,但对于其他输入,它会被终止,我无法理解为什么。

样本输入:

1
561473

输出:

2

样本输入:

1
10093

程序终止了。

在某些时候,我认为它可能是浮点异常,但我无法弄清楚原因。 我试着调试每一行代码,发现程序终止于这行代码:

while(ull(n%mem[j]) == 0) {

我仍然无法理解为什么此代码仅针对某些特定输入而中断。 我也试过没有类型铸造,但它仍然给我同样的问题。 我试图打印异常,但程序刚刚终止,它没有打印任何错误。

#include <iostream>
#include <string>
#include <climits>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
ull RANGE = sqrt(10000), num;
unsigned int i;
set<ull> arr;
ull mem [10000000];

bool isPrime(unsigned long long n) {
    if(n%2 == 0)
        return false;
    for( int i = 3; i <= sqrt(n); i+=2) {
        if(n%i == 0)
            return false;
    }
    return true;
}

void hungry() {
    while(true) {
        if(num > RANGE)
            break;
        if(isPrime(num))  {
            mem[i++] = num;
        }
        num += 2;
    }
}

int main() {
    ios_base::sync_with_stdio (false);
    cin.tie(NULL);
    num = 3; i = 1; mem [0] = 2;
    hungry();
    ull ip, n, temp;
    cin >> ip;
    while(ip) {
        cin >> n;
        arr.clear();
        temp = (ull) sqrt(n);
        if(temp > RANGE) {
            RANGE = temp;
            hungry();
        }
        if(n == 1)
            cout << 0 << "\n";
        else {
            while(n%2 == 0) {
                arr.insert(2);
                n = n/2;
            }
            for(int j = 1; mem[j] <= (ull)sqrt(n); j++){
                while(ull(n%mem[j]) == 0) {
                    arr.insert(mem[j]);
                    n = (ull)n/mem[j];
                }
            }

            if(n > 2)
                arr.insert(n);
            cout << arr.size() << "\n";
        }
        ip--;
    }
    return 0;
}

I am trying to print the number of prime factors of a given number. My code works fine for some inputs, but for other inputs it's getting terminated and I can't understand why.

Sample Input:

1
561473

Output:

2

Sample Input:

1
10093

And the program terminates.

At some point, I thought it might be floating point exceptions, but I couldn't figure out the reason. I tried to debug every line of code, and found that the program terminates on this line of code:

while(ull(n%mem[j]) == 0) {

I am still unable to understand why this code breaks only for some particular inputs. I have tried without type casting also, still it gives me the same problem. I tried to print the exception, but the program just terminated, it didn't print any error.

#include <iostream>
#include <string>
#include <climits>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
ull RANGE = sqrt(10000), num;
unsigned int i;
set<ull> arr;
ull mem [10000000];

bool isPrime(unsigned long long n) {
    if(n%2 == 0)
        return false;
    for( int i = 3; i <= sqrt(n); i+=2) {
        if(n%i == 0)
            return false;
    }
    return true;
}

void hungry() {
    while(true) {
        if(num > RANGE)
            break;
        if(isPrime(num))  {
            mem[i++] = num;
        }
        num += 2;
    }
}

int main() {
    ios_base::sync_with_stdio (false);
    cin.tie(NULL);
    num = 3; i = 1; mem [0] = 2;
    hungry();
    ull ip, n, temp;
    cin >> ip;
    while(ip) {
        cin >> n;
        arr.clear();
        temp = (ull) sqrt(n);
        if(temp > RANGE) {
            RANGE = temp;
            hungry();
        }
        if(n == 1)
            cout << 0 << "\n";
        else {
            while(n%2 == 0) {
                arr.insert(2);
                n = n/2;
            }
            for(int j = 1; mem[j] <= (ull)sqrt(n); j++){
                while(ull(n%mem[j]) == 0) {
                    arr.insert(mem[j]);
                    n = (ull)n/mem[j];
                }
            }

            if(n > 2)
                arr.insert(n);
            cout << arr.size() << "\n";
        }
        ip--;
    }
    return 0;
}

原文:https://stackoverflow.com/questions/39303820
更新时间:2023-09-11 14:09

最满意答案

WinForms控件具有名称,但这并不意味着您可以使用该名称作为C#标识符来访问它们。

你的PictureBox在EventHandler()只有一个命名的引用,即picture ,但是一旦控制离开那个引用超出范围的方法。

您需要再次找到控件,或者找到另一种引用生成的控件的方式。

所以:

var allPictureBoxes = this.Controls.Find("PictureBoxLM");
foreach (var pictureBox in allPictureBoxes)
{
    // ...
}

或者把它放在你的表格上:

List<PictureBox> pictureBoxList = new List<PictureBox>();

然后在EventHandler() ;

this.Controls.Add(picture);
pictureBoxList.Add(picture);

之后,您可以将其用于碰撞检测:

foreach (var pictureBox in pictureBoxList)
{
    // ...
}

WinForms controls have names, but that doesn't mean you can access them using that name as a C# identifier.

Your PictureBox only has a named reference within EventHandler(), namely picture, but once control leaves that method that reference goes out of scope.

You need to find the controls again, or find another way to reference the generated controls.

So either:

var allPictureBoxes = this.Controls.Find("PictureBoxLM");
foreach (var pictureBox in allPictureBoxes)
{
    // ...
}

Or put this on your form:

List<PictureBox> pictureBoxList = new List<PictureBox>();

And then in the EventHandler();

this.Controls.Add(picture);
pictureBoxList.Add(picture);

After which you can use this for your collision detection:

foreach (var pictureBox in pictureBoxList)
{
    // ...
}

相关问答

更多
  • pictureBox.Visible = true; pictureBox.Visible = false; pictureBox.Visible = true; pictureBox.Visible = false;
  • 尝试方法PictureBox.Refresh() (从Control继承)。 Try the method PictureBox.Refresh() (inherited from Control).
  • 我真的不知道你想做什么,但你可以尝试将对象发送到你的Access类: private void pictureBox1_Click(object sender, EventArgs e) { Access ac = new Access(); ac.PictureClicked(sender); } public void PictureClicked(Object Sender) { picBox = (PictureBox)Sender; ...
  • 你从未分配过Image ,对吗? 如果你想在PictureBox的图像上绘图,你需要首先通过为它指定一个带有PictureBox尺寸的位图来创建这个图像: Graph.Image = new System.Drawing.Bitmap(Graph.Width, Graph.Height); 你只需要这样做一次 ,如果你想在那里重绘任何东西,那么可以重复使用图像。 然后,您可以随后使用此图像进行绘图。 有关更多信息, 请参阅文档 。 顺便说一句,这完全独立于在Paint事件处理程序中绘制PictureBox ...
  • Label控件支持透明度。 只是设计师不会让您正确放置标签。 PictureBox控件不是容器控件,因此窗体成为标签的父项。 所以你看到表单的背景。 通过在窗体构造函数中添加一些代码来解决这个问题。 您需要更改标签的父属性并重新计算它的位置,因为它现在相对于图片框而不是窗体。 喜欢这个: public Form1() { InitializeComponent(); var pos = this.PointToScreen(label1.Location); ...
  • 你现在正在做的只是冻结用户界面。 请改用System.Windows.Forms.Timer 。 将计时器从工具箱中拖放到表单上。 然后创建一些Timer可以访问的字段,以存储您的照片和当前的pic位置: private List pics = new List(); private int currentPic = 0; 最后,用你想要显示的图片加载它,然后启动Timer来完成它们: pics.Clear(); pics.AddRange(date.Where(x => ...
  • WinForms控件具有名称,但这并不意味着您可以使用该名称作为C#标识符来访问它们。 你的PictureBox在EventHandler()只有一个命名的引用,即picture ,但是一旦控制离开那个引用超出范围的方法。 您需要再次找到控件,或者找到另一种引用生成的控件的方式。 所以: var allPictureBoxes = this.Controls.Find("PictureBoxLM"); foreach (var pictureBox in allPictureBoxes) { // ...
  • Invalidate()你的PictureBox,所以它重绘自己: Bitmap frame = byteArrayToImage(buff) as Bitmap; using (var graphics = Graphics.FromImage(pictureBox1.Image)) { graphics.DrawImage(frame, left, top); } pictureBox1.Invalidate(); 如果您需要它是线程安全的,那么: pictureBox1.Invoke((Me ...
  • 在winforms中,您将不得不修改 PictureBox.Image 的alpha 。 要快速执行此操作,请使用ColorMatrix ! 这是一个例子: 跟踪栏代码: Image original = null; private void trackBar1_Scroll(object sender, EventArgs e) { if (original == null) original = (Bitmap) pictureBox1.Image.Clone(); pictureBo ...
  • 您可以将图像读入图片框而不锁定它,如下所示 Image img; string file = @"d:\a.jpg"; using (Bitmap bmp = new Bitmap(file)) { img = new Bitmap(bmp); current_pic.Image = img; } if (File.Exists(file)) { File.Delete(file); current_pic.Image.Save(file, ImageFormat.Jpeg); ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)