Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:45:34+00:00 2026-06-14T22:45:34+00:00

My code in C++ long long N=1000000000000LL; long long a = N; mpz_class v;

  • 0

My code in C++

   long long N=1000000000000LL;
   long long a = N;
   mpz_class v;
   mpz_mul(v, a, a); 
   cout<<v<<endl; //I want this to show 1000000000002000000000001
   long long U=((sqrt(4*N+v)-1)/4);  //not sure how to do this in GMP at all
   cout << U << endl; //should show 250000000000

This is a snippet that shows what kind of operations I want to do. But I am not experienced enough with GMP to get it down, and the documentation is unclear to me. How do I correct all this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:45:35+00:00Added an answer on June 14, 2026 at 10:45 pm

    mpz_class has no constructor from long long (it only goes up to unsigned long), so you’d have to use an intermediate string:

    #include <gmpxx.h>
    #include <iostream>
    #include <string>
    
    int main()
    {
        long long N = 1000000000000LL;
        mpz_class a(std::to_string(N).c_str());
        mpz_class v = a*a;
        std::cout << v << '\n'; // shows 1000000000000000000000000
        std::cout << (a+1) * (a+1) << '\n'; // THIS shows 1000000000002000000000001
    
        mpz_class U = ((sqrt(4*a+v)-1)/4);
        std::cout << U << '\n'; // shows 250000000000
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to measure time memory allocation using this code: long AForMemory = DateTime.Now.Ticks;
i have this long code to show today's date & time in a form
Hello everyone :) I'm sorry for the long code listing, but I'm not sure
In this code long timestamp=1332782463298; Date d=new Date(timestamp); date=d.toLocaleString(); date is always current date.
iam adding a contact to the device using this code long Contact_Id = 100;
First of all, do not be overwhelmed by the long code, I just put
I want to compare two hexadecimal(stored in long) below is my code long constant
I have this long code about a table width some various content. It is
I think I have been working on this code too long. Anyway here is
This is my code: JSONStringer result = new JSONStringer(); for (long i = start;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.