The two men collaborated often. Hardy remembered a slight man, of medium height, with eyes through which some light seemed to shine. Ramanujan remained a strict vegetarian, cooking all his own food in his rooms, and when he fell mysteriously ill in 1917, Hardy thought his vegetarianism contributed to his failing health. Shared Fascination

Years later, Hardy took some pains to dispel the idea, perhaps a byproduct of subtle English racism, that Ramanujan was some sort of Asian curiosity - either an ''inspired idiot'' or ''some mysterious manifestation of the immemorial wisdom of the East.'' On the contrary, in Hardy's eyes he was a deliberate rationalist, often shrewd, and not nearly so religious as his dietary habits made him appear.

They shared a fascination with numbers as almost living things, or characters in a story. They thought about round numbers, defined as numbers with only small factors, like 300, 2#2X3X5#2. They worked on the question of how common such numbers are, in strict mathematical terms, and on many problems more difficult to put into words. 'A Very Interesting Number'

One day after Ramanujan fell ill, Hardy visited him in a taxicab and remarked that the cab's number had been rather uninteresting - 1729, or 7X13X19. ''No, it is a very interesting number,'' Ramanujan responded, as Hardy later told the story. ''It is the smallest number expressible as a sum of two cubes in two different ways.'' (It is the sum of 1X1X1 and 12X12X12, and it is also the sum of 9X9X9 and 10X10X10.) Hardy understood and appreciated Ramanujan more than any of his contemporaries. But even he could not see beyond the blinkers of his time and place. To him, Ramanujan's story was ultimately a tragedy - of inadequate education and of genius unguided. When he finally came to assess the younger mathematician's work and its likely influence on the future of his subject, he expressed disappointment.

''It has not the simplicity and the inevitableness of the very greatest work,'' Hardy wrote in 1927. ''It would be greater if it were less strange.''

Few mathematicians accept that assessment today, as strangeness comes into the light and Hardy recedes into Ramanujan's greater shadow.

''Hardy thought it was a shame that Ramanujan wasn't born a hundred years earlier,'' Dr. Askey said. That was the great age of formulas, the era of ground-laying work by such mathematicians as Euler and Gauss. ''My comment is that it's a shame Ramanujan wasn't born a hundred years later,'' he said. ''We're trying to do problems in several variables now - the problems are harder, and it would be marvelous to have somebody with his intuition to help get started.''