Adding affiliation due to a 1-month visit during a salary gap I worked at University A and did a research stay during one month at University B; I was not paid by them, but I got funding (from a third agency) thanks to them for accepting my visit during a salary gap, before going to University C. 

About 80% of the paper I want to submit I wrote in my university, but I finished it at University B during said stay, even though my original aim of being at University B was another research topic. 

I would like to put U A and U B both as affiliations, since the environment in U B boosted my research (and I don't want to be less thankful than I ought). Is it justified to write both affiliations? Or should I write only University A as affiliation and thank for hospitality to University B and my host there?
I don't think that the effect will be different no matter what you put, but the latter (...hospitality...) version seems marginally more honest. Being a visitor at a prestigious place caries some cachet of course. 

I don't think that a one month salary gap is going to be any issue, if it is even noticed. But you will mention the funding agency, of course.