Just think in terms of set-associative cache mapping used in cache organization.
Number of pages = (Total Virtual address space) / (Page size)
=(2^40) / (2^13) = (2)^27
No. of bits required to uniquely identify a page is 27
Assume page as a block for simplicity
Like in the cache we take each main memory block and map it to a block in the cache
Number of blocks = 2^27, Number of bits to uniquely identify a block =27
So here we are using 4 way set associative mapping and the total number of sets = 32
Number of bits required to uniquely identify a set =5
So number of tag bits = 27-5 = 22 bits
Here logic is the same just assume page bits as block bits and subtract set bits from them we can get tag bits.
The answer is 27-5 = 22 tag bits