Son_Nguyen's blog

By Son_Nguyen, history, 9 years ago, In English

Hello, I have a problem need to solve:

S(n) = 1^k + 2^k +..+n^k

input: n<=10^9, k<=40

output: S(n)%(10^9+7).

One more issue:

how to calculate ((n^k)/x)%p which very big n and k.

Thank for helping me.

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it

By Son_Nguyen, history, 9 years ago, In English

Hello everybody. That is my code to show binary a decimal number. It's right when a>=0 but when a<0 that can't work, infinite loop. And I don't know what wrong in this code. Can you help me to solve? Thank so much!

void bi(int a)
{
        if(a==0)
            return;
        bi(a>>1);
        cout<<(a & (1));
}

//I have a nother code and it's right in both case. However I want to know what happen with this code. Sorry for my bad English

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Son_Nguyen, 9 years ago, In English

Hello everybody, my English not good, I wish many people can understand what I wrote :D You know "|" and "||" are meaning "or", "&" and "&&" are meaning "and" then what is difference ? Look at this code

int a = 0,b = 1;
if(b||a++);
cout<<a;

output: 0

int a = 0,b = 1;
if(b|a++);
cout<<a;

output: 1 I don't know why but I think || and && is smart, in this example when b==1 (true) then b "or" something is true, so "||" don't care after if sentese true in anyway. And "&&" is the same,

int a = 0,b = 1;
if(a && b++);
cout<<b;
int a = 0,b = 1;
if(a & b++);
cout<<b;

let try and see :). That is my second blog, My first blog is very bad, I wish this blog is better, sorry because my english is very bad. Thank for reading !

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it