class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param n int整型 
     * @return bool布尔型
     */
    bool happynum(int n) {
        // write code here
        multiset<int> mst;
        while(n!=1){
        	if(mst.count(n)){
        		return false;
			}
			mst.insert(n);
			int t=n;
			int sum=0;
			while(t!=0){
				sum=sum+(t%10)*(t%10);
				t=t/10;
			}
			n=sum;
		}
		return true;
    }
};