the problem is when the hackerrank inputs the following
10
5351871996120528
2248813659738258
2494359640703601
6044763399160734
3271269997212342
4276346434761561
2372239019637533
5624204919070546
9493965694520825
8629828692375133
My code gives the wrong output.
The output is supposed to be
578351320
404664464
20752136
999516029
743537718
323730244
174995256
593331567
136582381
305527433
So what changes should I make to get my code give the correct output.
Please help me.
The code works but I don't understand several things.
1) Doesn't "unsigned long long n " require datatype like float or int?Why is the compiler accepting "unsigned long long n " without int or float?
2)What is "constexpr "?
3)What is "static_assert"?
4)Finally, what is " for( auto n : test_data )"? I've only used "for" for loops till now. I don't understand why we have " auto n : test_data" inside it.
) Doesn't "unsigned long long n " require datatype like float or int?Why is the compiler accepting "unsigned long long n " without int or float?
unsigned is the data type.
What is "constexpr "?
it is an expression the value of which can be determined at compile time, and is const.
What is "static_assert"?
static_assert creates a compiler error message when the expression is true (or false I forget)
Finally, what is " for( auto n : test_data )"? I've only used "for" for loops till now. I don't understand why we have " auto n : test_data" inside it.
No. The data type is unsigned long long, though you could call it an unsigned long long.
@Gamemaster007: There are multiple versions of integral types. From smallest range to longest, you have char (technically an integral type), short, int, long, and long long. Each one is defined to be at least as large as the one before it. On my system, a char is 8 bits, a short is 16 bits, int and long are 32 bits, and long long is 64.
unsigned (as you may well know) just means that the number doesn't have a 'sign', i.e. all the values are positive. This means that since it doesn't have to store all the negative numbers, it can get numbers approximately twice as large. e.g. for char the range changes from -128 - 127; to 0 - 255.
Also, static_assert throws a compiler error if the parameter is false.
The constexpr in constexprunsignedlonglong MOD = 1000000007 ; implies const and specifies that the value can be evaluated at compile-time. http://www.stroustrup.com/C++11FAQ.html#constexpr
In this particular case, the effect is the same as if we had written: constunsignedlonglong MOD = 1000000007 ;
static_assert is an assertion checked at compile-time. http://www.stroustrup.com/C++11FAQ.html#static_assert static_assert( ( (MOD*MOD) / MOD ) == MOD, "integer overflow" ) ;
verifies at compile-time that MOD*MOD (1000000007*1000000007) does not cause an integer overflow.
If the assertion holds, the line has no effect; if it does not, there is a compile-time error.