S数
题目大意:
定义f(x)为x各位数字之和,问[l,r]区间内有多少数满足f(x)*f(x)=f(x*x)。
思路:
刚开始暴力打表,发现所有数的位都在0..3之间,然后直接枚举每一位,最坏情况下运算规模大概是9^4。
然后本来的表也不舍得扔掉,所以就一半打表一半标算。
然后发现打表+标算其实反而会比直接上标算慢。
1 #include<cstdio> 2 #include<cctype> 3 #include<algorithm> 4 inline int getint() { 5 register char ch; 6 while(!isdigit(ch=getchar())); 7 register int x=ch^'0'; 8 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); 9 return x; 10 } 11 const int table[]={-1,0,1,2,3,10,11,12,13,20,21,22,30,31,100,101,102,103,110,111,112,113,120,121,122,130,200,201,202,210,211,212,220,221,300,301,310,311,1000,1001,1002,1003,1010,1011,1012,1013,1020,1021,1022,1030,1031,1100,1101,1102,1103,1110,1111,1112,1113,1120,1121,1122,1130,1200,1201,1202,1210,1211,1212,1220,1300,1301,2000,2001,2002,2010,2011,2012,2020,2021,2022,2100,2101,2102,2110,2111,2120,2121,2200,2201,2202,2210,2211,3000,3001,3010,3011,3100,3101,3110,3111,10000,10001,10002,10003,10010,10011,10012,10013,10020,10021,10022,10030,10031,10100,10101,10102,10103,10110,10111,10112,10113,10120,10121,10122,10130,10200,10201,10202,10210,10211,10212,10220,10221,10300,10310,11000,11001,11002,11003,11010,11011,11012,11013,11020,11021,11022,11030,11031,11100,11101,11102,11103,11110,11111,11112,11113,11120,11121,11122,11130,11200,11201,11202,11210,11211,11220,11300,12000,12001,12002,12010,12011,12012,12020,12100,12101,12102,12110,12111,12120,12200,12201,12202,13000,13001,13010,13011,20000,20001,20002,20010,20011,20012,20020,20021,20022,20100,20101,20102,20110,20111,20112,20120,20121,20122,20200,20201,20210,20211,20220,20221,21000,21001,21002,21010,21011,21020,21021,21100,21101,21102,21110,21111,21200,21201,21210,22000,22001,22002,22010,22011,22020,22100,22101,22102,22110,22111,30000,30001,30010,30011,30100,30101,30110,30111,31000,31001,31010,31011,31100,31101,31110,31111,100000,100001,100002,100003,100010,100011,100012,100013,100020,100021,100022,100030,100031,100100,100101,100102,100103,100110,100111,100112,100113,100120,100121,100122,100130,100200,100201,100202,100210,100211,100212,100220,100221,100300,100301,100310,100311,101000,101001,101002,101003,101010,101011,101012,101013,101020,101021,101022,101030,101031,101100,101101,101102,101103,101110,101111,101112,101113,101120,101121,101122,101130,101200,101201,101202,101210,101211,101212,101220,101300,101301,102000,102001,102002,102010,102011,102012,102020,102021,102022,102100,102101,102102,102110,102111,102120,102121,102200,102210,103000,103001,103100,103101,110000,110001,110002,110003,110010,110011,110012,110013,110020,110021,110022,110030,110031,110100,110101,110102,110103,110110,110111,110112,110113,110120,110121,110122,110130,110200,110201,110202,110210,110211,110212,110220,110221,110300,110310,111000,111001,111002,111003,111010,111011,111012,111013,111020,111021,111022,111030,111031,111100,111101,111102,111103,111110,111111,111112,111120,111121,111130,111200,111201,111202,111210,111211,111220,111300,112000,112001,112002,112010,112011,112012,112020,112100,112101,112102,112110,112111,112200,113000,113001,120000,120001,120002,120010,120011,120012,120020,120100,120101,120102,120110,120111,120112,120120,120200,120201,121000,121001,121002,121010,121011,121020,121100,121101,121102,121110,121111,121200,121201,122000,122001,122002,122010,122011,122020,130000,130001,130010,130011,130100,130101,130110,130111,200000,200001,200002,200010,200011,200012,200020,200021,200022,200100,200101,200102,200110,200111,200112,200120,200121,200122,200200,200201,200202,200210,200211,200212,200220,200221,201000,201001,201002,201010,201011,201012,201020,201021,201022,201100,201101,201110,201111,201120,201121,201200,201201,201210,201211,201220,202000,202001,202002,202010,202011,202012,202100,202101,202110,202111,202200,202210,210000,210001,210002,210010,210011,210020,210021,210100,210101,210102,210110,210111,210200,210201,210202,210210,210211,211000,211001,211002,211010,211011,211020,211021,211100,211101,211110,211111,212000,212001,212002,212010,212011,212100,212101,220000,220001,220002,220010,220011,220020,220100,220101,220102,220110,220111,220200,220201,221000,221001,221002,221010,221011,221020,221100,221101,221110,300000,300001,300010,300011,300100,300101,300110,300111,301000,301001,301010,301011,301100,301101,301110,301111,310000,310001,310010,310011,310100,310101,310110,310111,311000,311001,311010,311011,311100,311101,311110,1000000,1000001,1000002,1000003,1000010,1000011,1000012,1000013,1000020,1000021,1000022,1000030,1000031,1000100,1000101,1000102,1000103,1000110,1000111,1000112,1000113,1000120,1000121,1000122,1000130,1000200,1000201,1000202,1000210,1000211,1000212,1000220,1000221,1000300,1000301,1000310,1000311,1001000,1001001,1001002,1001003,1001010,1001011,1001012,1001013,1001020,1001021,1001022,1001030,1001031,1001100,1001101,1001102,1001103,1001110,1001111,1001112,1001113,1001120,1001121,1001122,1001130,1001200,1001201,1001202,1001210,1001211,1001212,1001220,1001300,1001301,1002000,1002001,1002002,1002010,1002011,1002012,1002020,1002021,1002022,1002100,1002101,1002102,1002110,1002111,1002120,1002121,1002200,1002201,1002202,1002210,1002211,1003000,1003010,1003100,1003110,1010000,1010001,1010002,1010003,1010010,1010011,1010012,1010013,1010020,1010021,1010022,1010030,1010031,1010100,1010101,1010102,1010103,1010110,1010111,1010112,1010113,1010120,1010121,1010122,1010130,1010200,1010201,1010202,1010210,1010211,1010212,1010220,1010221,1010300,1010310,1011000,1011001,1011002,1011003,1011010,1011011,1011012,1011013,1011020,1011021,1011022,1011030,1011031,1011100,1011101,1011102,1011103,1011110,1011111,1011112,1011113,1011120,1011121,1011122,1011130,1011200,1011201,1011202,1011210,1011211,1011220,1011300,1012000,1012001,1012002,1012010,1012011,1012012,1012020,1012100,1012101,1012110,1012111,1012120,1012200,1013000,1013010,1020000,1020001,1020002,1020010,1020011,1020012,1020020,1020021,1020022,1020100,1020101,1020102,1020110,1020111,1020112,1020120,1020121,1020122,1020200,1020210,1020220,1021000,1021001,1021002,1021010,1021011,1021020,1021021,1021100,1021101,1021102,1021110,1021111,1021200,1021210,1022000,1022001,1022002,1022100,1030000,1030001,1030010,1030011,1031000,1031001,1031010,1031011,1100000,1100001,1100002,1100003,1100010,1100011,1100012,1100013,1100020,1100021,1100022,1100030,1100031,1100100,1100101,1100102,1100103,1100110,1100111,1100112,1100113,1100120,1100121,1100122,1100130,1100200,1100201,1100202,1100210,1100211,1100212,1100220,1100221,1100300,1100301,1100310,1100311,1101000,1101001,1101002,1101003,1101010,1101011,1101012,1101013,1101020,1101021,1101022,1101030,1101031,1101100,1101101,1101102,1101103,1101110,1101111,1101112,1101113,1101120,1101121,1101122,1101130,1101200,1101201,1101202,1101210,1101211,1101212,1101220,1101300,1101301,1102000,1102001,1102002,1102010,1102011,1102020,1102100,1102101,1102102,1102110,1102111,1102120,1102200,1102210,1103000,1103100,1110000,1110001,1110002,1110003,1110010,1110011,1110012,1110013,1110020,1110021,1110022,1110030,1110031,1110100,1110101,1110102,1110103,1110110,1110111,1110112,1110120,1110121,1110130,1110200,1110201,1110202,1110210,1110211,1110220,1110300,1110310,1111000,1111001,1111002,1111003,1111010,1111011,1111012,1111013,1111020,1111021,1111022,1111030,1111031,1111100,1111101,1111102,1111103,1111110,1111111,1111112,1111120,1111121,1111200,1111201,1111202,1111210,1111211,1111300,1112000,1112001,1112002,1112010,1112011,1112020,1112100,1112101,1112110,1112200,1113000,1120000,1120001,1120002,1120010,1120011,1120012,1120020,1120100,1120101,1120102,1120110,1120111,1120120,1120200,1121000,1121001,1121002,1121010,1121011,1121020,1121100,1121101,1121102,1121110,1121111,1122000,1122001,1122002,1130000,1130001,1130010,1130011,1200000,1200001,1200002,1200010,1200011,1200012,1200020,1200100,1200101,1200102,1200110,1200111,1200112,1200120,1200200,1200201,1200202,1201000,1201001,1201002,1201010,1201011,1201012,1201020,1201100,1201101,1201110,1201111,1201120,1201200,1201201,1202000,1202001,1202002,1202010,1210000,1210001,1210002,1210010,1210011,1210020,1210100,1210101,1210102,1210110,1210111,1210200,1210201,1210202,1211000,1211001,1211002,1211010,1211011,1211020,1211100,1211101,1211110,1211111,1212000,1212001,1212002,1212010,1220000,1220001,1220002,1220010,1220011,1220020,1220100,1220101,1220102,1220110,1220200,1300000,1300001,1300010,1300011,1300100,1300101,1300110,1300111,1301000,1301001,1301010,1301011,1301100,1301101,1301110,1301111,2000000,2000001,2000002,2000010,2000011,2000012,2000020,2000021,2000022,2000100,2000101,2000102,2000110,2000111,2000112,2000120,2000121,2000122,2000200,2000201,2000202,2000210,2000211,2000212,2000220,2000221,2001000,2001001,2001002,2001010,2001011,2001012,2001020,2001021,2001022,2001100,2001101,2001102,2001110,2001111,2001112,2001120,2001121,2001122,2001200,2001201,2001202,2001210,2001211,2001212,2001220,2002000,2002001,2002010,2002011,2002020,2002021,2002100,2002101,2002110,2002111,2002120,2002121,2002200,2002201,2002210,2002211,2010000,2010001,2010002,2010010,2010011,2010012,2010020,2010021,2010022,2010100,2010101,2010110,2010111,2010120,2010121,2010200,2010201,2010210,2010211,2010220,2010221,2011000,2011001,2011002,2011010,2011011,2011012,2011100,2011101,2011110,2011111,2011200,2011201,2011210,2011211,2012000,2012001,2012010,2012011,2012100,2012110,2012200,2020000,2020001,2020002,2020010,2020011,2020012,2020020,2020021,2020022,2020100,2020101,2020110,2020111,2020120,2020121,2021000,2021001,2021002,2021010,2021011,2021100,2021101,2021110,2021111,2022000,2022001,2022100,2100000,2100001,2100002,2100010,2100011,2100020,2100021,2100100,2100101,2100102,2100110,2100111,2100200,2100201,2100202,2100210,2100211,2101000,2101001,2101002,2101010,2101011,2101020,2101021,2101100,2101101,2101102,2101110,2101111,2102000,2102001,2102010,2102020,2102100,2102101,2102110,2110000,2110001,2110002,2110010,2110011,2110020,2110021,2110100,2110101,2110110,2110111,2110200,2110201,2110210,2111000,2111001,2111002,2111010,2111011,2111100,2111101,2111110,2111111,2120000,2120001,2120002,2120010,2120011,2120020,2120100,2120101,2120110,2121000,2121001,2121002,2121010,2121011,2200000,2200001,2200002,2200010,2200011,2200020,2200100,2200101,2200102,2200110,2200111,2200200,2200201,2200202,2201000,2201001,2201002,2201010,2201011,2201020,2201100,2201101,2201110,2201111,2202000,2202001,2202010,2210000,2210001,2210002,2210010,2210011,2210020,2210100,2210101,2210110,2210200,2210201,2211000,2211001,2211002,2211010,2211011,2211100,2211101,3000000,3000001,3000010,3000011,3000100,3000101,3000110,3000111,3001000,3001001,3001010,3001011,3001100,3001101,3001110,3001111,3010000,3010001,3010010,3010011,3010100,3010101,3010110,3010111,3011000,3011001,3011010,3011011,3011100,3011101,3011110,3011111,3100000,3100001,3100010,3100011,3100100,3100101,3100110,3100111,3101000,3101001,3101010,3101011,3101100,3101101,3101110,3101111,3110000,3110001,3110010,3110011,3110100,3110101,3110110,3111000,3111001,3111010,3111011,3111100,3111101,10000000,10000001,10000002,10000003,10000010,10000011,10000012,10000013,10000020,10000021,10000022,10000030,10000031,10000100,10000101,10000102,10000103,10000110,10000111,10000112,10000113,10000120,10000121,10000122,10000130,10000200,10000201,10000202,10000210,10000211,10000212,10000220,10000221,10000300,10000301,10000310,10000311,10001000,10001001,10001002,10001003,10001010,10001011,10001012,10001013,10001020,10001021,10001022,10001030,10001031,10001100,10001101,10001102,10001103,10001110,10001111,10001112,10001113,10001120,10001121,10001122,10001130,10001200,10001201,10001202,10001210,10001211,10001212,10001220,10001300,10001301,10002000,10002001,10002002,10002010,10002011,10002012,10002020,10002021,10002022,10002100,10002101,10002102,10002110,10002111,10002120,10002121,10002200,10002201,10002202,10002210,10002211,10003000,10003001,10003010,10003011,10003100,10003101,10003110,10003111,10010000,10010001,10010002,10010003,10010010,10010011,10010012,10010013,10010020,10010021,10010022,10010030,10010031,10010100,10010101,10010102,10010103,10010110,10010111,10010112,10010113,10010120,10010121,10010122,10010130,10010200,10010201,10010202,10010210,10010211,10010212,10010220,10010221,10010300,10010310,10011000,10011001,10011002,10011003,10011010,10011011,10011012,10011013,10011020,10011021,10011022,10011030,10011031,10011100,10011101,10011102,10011103,10011110,10011111,10011112,10011113,10011120,10011121,10011122,10011130,10011200,10011201,10011202,10011210,10011211,10011220,10011300,10012000,10012001,10012002,10012010,10012011,10012012,10012020,10012100,10012101,10012102,10012110,10012111,10012120,10012200,10012201,10012202,10013000,10013001,10013010,10013011,10020000,10020001,10020002,10020010,10020011,10020012,10020020,10020021,10020022,10020100,10020101,10020102,10020110,10020111,10020112,10020120,10020121,10020122,10020200,10020201,10020210,10020211,10020220,10020221,10021000,10021001,10021002,10021010,10021011,10021020,10021021,10021100,10021101,10021102,10021110,10021111,10021200,10021201,10021210,10022000,10022010,10022020,10022100,10022110,10030000,10030001,10030100,10030101,10031000,10031001,10031100,10031101,10100000,10100001,10100002,10100003,10100010,10100011,10100012,10100013,10100020,10100021,10100022,10100030,10100031,10100100,10100101,10100102,10100103,10100110,10100111,10100112,10100113,10100120,10100121,10100122,10100130,10100200,10100201,10100202,10100210,10100211,10100212,10100220,10100221,10100300,10100301,10100310,10100311,10101000,10101001,10101002,10101003,10101010,10101011,10101012,10101013,10101020,10101021,10101022,10101030,10101031,10101100,10101101,10101102,10101103,10101110,10101111,10101112,10101113,10101120,10101121,10101122,10101130,10101200,10101201,10101202,10101210,10101211,10101212,10101220,10101300,10101301,10102000,10102001,10102002,10102010,10102011,10102012,10102020,10102021,10102022,10102100,10102101,10102102,10102110,10102111,10102120,10102121,10102200,10102210,10103000,10103001,10103100,10103101,10110000,10110001,10110002,10110003,10110010,10110011,10110012,10110013,10110020,10110021,10110022,10110030,10110031,10110100,10110101,10110102,10110103,10110110,10110111,10110112,10110113,10110120,10110121,10110122,10110130,10110200,10110201,10110202,10110210,10110211,10110212,10110220,10110221,10110300,10110310,10111000,10111001,10111002,10111003,10111010,10111011,10111012,10111013,10111020,10111021,10111022,10111030,10111031,10111100,10111101,10111102,10111110,10111111,10111112,10111120,10111121,10111130,10111200,10111201,10111210,10111211,10111220,10111300,10112000,10112001,10112002,10112010,10112011,10112012,10112020,10112100,10112101,10112110,10112111,10112200,10113000,10113001,10120000,10120001,10120002,10120010,10120011,10120012,10120020,10120100,10120101,10120102,10120110,10120111,10120112,10120120,10120200,10120201,10121000,10121001,10121002,10121010,10121011,10121100,10121101,10121110,10121111,10121200,10122000,10130000,10130001,10130100,10130101,10200000,10200001,10200002,10200010,10200011,10200012,10200020,10200021,10200022,10200100,10200101,10200102,10200110,10200111,10200112,10200120,10200121,10200122,10200200,10200210,10200220,10201000,10201001,10201002,10201010,10201011,10201012,10201020,10201021,10201022,10201100,10201101,10201110,10201111,10201120,10201121,10201200,10201210,10201220,10202000,10202001,10202002,10202100,10202101,10202200,10210000,10210001,10210002,10210010,10210011,10210020,10210021,10210100,10210101,10210102,10210110,10210111,10210200,10210210,10211000,10211001,10211002,10211010,10211011,10211020,10211021,10211100,10211101,10211110,10211111,10212000,10212001,10212002,10212100,10220000,10220001,10220002,10220010,10220011,10220020,10221000,10221001,10221002,10300000,10300001,10300010,10300011,10300100,10300101,10300110,10300111,10310000,10310001,10310010,10310011,10310100,10310101,10310110,10310111,11000000,11000001,11000002,11000003,11000010,11000011,11000012,11000013,11000020,11000021,11000022,11000030,11000031,11000100,11000101,11000102,11000103,11000110,11000111,11000112,11000113,11000120,11000121,11000122,11000130,11000200,11000201,11000202,11000210,11000211,11000212,11000220,11000221,11000300,11000301,11000310,11000311,11001000,11001001,11001002,11001003,11001010,11001011,11001012,11001013,11001020,11001021,11001022,11001030,11001031,11001100,11001101,11001102,11001103,11001110,11001111,11001112,11001113,11001120,11001121,11001122,11001130,11001200,11001201,11001202,11001210,11001211,11001212,11001220,11001300,11001301,11002000,11002001,11002002,11002010,11002011,11002012,11002020,11002021,11002022,11002100,11002101,11002102,11002110,11002111,11002120,11002121,11002200,11002201,11002202,11002210,11002211,11003000,11003010,11003100,11003110,11010000,11010001,11010002,11010003,11010010,11010011,11010012,11010013,11010020,11010021,11010022,11010030,11010031,11010100,11010101,11010102,11010103,11010110,11010111,11010112,11010113,11010120,11010121,11010122,11010130,11010200,11010201,11010202,11010210,11010211,11010212,11010220,11010221,11010300,11010310,11011000,11011001,11011002,11011003,11011010,11011011,11011012,11011020,11011021,11011030,11011100,11011101,11011102,11011103,11011110,11011111,11011112,11011120,11011121,11011130,11011200,11011201,11011202,11011210,11011211,11011220,11011300,11012000,11012001,11012002,11012010,11012011,11012020,11012100,11012101,11012110,11012111,11012120,11012200,11013000,11013010,11020000,11020001,11020002,11020010,11020011,11020012,11020020,11020021,11020022,11020100,11020101,11020102,11020110,11020111,11020112,11020200,11021000,11021001,11021002,11021010,11021011,11021020,11021100,11021101,11021102,11021110,11021111,11021200,11022000,11022100,11030000,11030001,11031000,11031001,11100000,11100001,11100002,11100003,11100010,11100011,11100012,11100013,11100020,11100021,11100022,11100030,11100031,11100100,11100101,11100102,11100103,11100110,11100111,11100112,11100120,11100121,11100130,11100200,11100201,11100202,11100210,11100211,11100220,11100300,11100301,11100310,11101000,11101001,11101002,11101003,11101010,11101011,11101012,11101013,11101020,11101021,11101022,11101030,11101031,11101100,11101101,11101102,11101103,11101110,11101111,11101112,11101120,11101121,11101200,11101201,11101202,11101210,11101211,11101300,11101301,11102000,11102001,11102002,11102010,11102011,11102020,11102100,11102101,11102102,11102110,11102111,11102200,11103000,11103100,11110000,11110001,11110002,11110003,11110010,11110011,11110012,11110013,11110020,11110021,11110022,11110030,11110031,11110100,11110101,11110102,11110103,11110110,11110111,11110112,11110120,11110121,11110130,11110200,11110201,11110202,11110210,11110211,11110220,11110300,11110310,11111000,11111001,11111002,11111003,11111010,11111011,11111012,11111020,11111021,11111030,11111100,11111101,11111102,11111110,11111111,11111120,11111200,11111201,11111210,11112000,11112001,11112002,11112010,11112011,11112020,11112100,11112101,11112110,11113000,11120000,11120001,11120002,11120010,11120011,11120012,11120020,11120100,11120101,11120102,11120110,11120111,11120200,11121000,11121001,11121002,11121010,11121011,11121100,11121101,11122000,11130000,11130001,11200000,11200001,11200002,11200010,11200011,11200012,11200020,11200100,11200101,11200102,11200110,11200111,11200120,11200200,11201000,11201001,11201002,11201010,11201011,11201012,11201020,11201100,11201101,11201110,11201111,11201200,11202000,11202001,11202002,11210000,11210001,11210002,11210010,11210011,11210020,11210100,11210101,11210102,11210110,11210111,11210200,11211000,11211001,11211002,11211010,11211011,11211020,11211100,11211101,11211110,11220000,11220001,11220002,11220010,11220011,11220020,11300000,11300001,11300010,11300011,11300100,11300101,11300110,12000000,12000001,12000002,12000010,12000011,12000012,12000020,12000100,12000101,12000102,12000110,12000111,12000112,12000120,12000200,12000201,12000202,12001000,12001001,12001002,12001010,12001011,12001012,12001020,12001100,12001101,12001102,12001110,12001111,12001112,12001120,12001200,12001201,12001202,12002000,12002001,12002010,12002011,12002020,12010000,12010001,12010002,12010010,12010011,12010012,12010020,12010100,12010101,12010110,12010111,12010120,12010200,12010201,12011000,12011001,12011002,12011010,12011011,12011100,12011101,12011110,12011111,12011200,12011201,12012000,12012001,12012010,12020000,12020001,12020002,12020010,12020011,12020012,12020020,12020100,12020101,12100000,12100001,12100002,12100010,12100011,12100020,12100100,12100101,12100102,12100110,12100111,12100200,12100201,12100202,12101000,12101001,12101002,12101010,12101011,12101020,12101100,12101101,12101102,12101110,12101111,12102000,12102001,12102010,12102020,12110000,12110001,12110002,12110010,12110011,12110020,12110100,12110101,12110110,12110111,12110200,12110201,12111000,12111001,12111002,12111010,12111011,12111100,12111101,12111110,12120000,12120001,12120002,12120010,12120011,12120020,12120100,12120101,12200000,12200001,12200002,12200010,12200011,12200020,12200100,12200101,12200102,12200110,12200200,12201000,12201001,12201002,12201010,12201011,12201020,12201100,12201101,12202000,12202001,13000000,13000001,13000010,13000011,13000100,13000101,13000110,13000111,13001000,13001001,13001010,13001011,13001100,13001101,13001110,13001111,13010000,13010001,13010010,13010011,13010100,13010101,13010110,13010111,13011000,13011001,13011010,13011100,13011101,13011110,20000000,20000001,20000002,20000010,20000011,20000012,20000020,20000021,20000022,20000100,20000101,20000102,20000110,20000111,20000112,20000120,20000121,20000122,20000200,20000201,20000202,20000210,20000211,20000212,20000220,20000221,20001000,20001001,20001002,20001010,20001011,20001012,20001020,20001021,20001022,20001100,20001101,20001102,20001110,20001111,20001112,20001120,20001121,20001122,20001200,20001201,20001202,20001210,20001211,20001212,20001220,20002000,20002001,20002002,20002010,20002011,20002012,20002020,20002021,20002022,20002100,20002101,20002102,20002110,20002111,20002120,20002121,20002200,20002201,20002202,20002210,20002211,20010000,20010001,20010002,20010010,20010011,20010012,20010020,20010021,20010022,20010100,20010101,20010102,20010110,20010111,20010112,20010120,20010121,20010122,20010200,20010201,20010202,20010210,20010211,20010212,20010220,20010221,20011000,20011001,20011010,20011011,20011020,20011021,20011100,20011101,20011110,20011111,20011120,20011121,20011200,20011201,20011210,20011211,20011220,20012000,20012001,20012010,20012011,20012020,20012100,20012101,20012110,20012111,20012120,20012200,20012201,20020000,20020001,20020002,20020010,20020011,20020012,20020100,20020101,20020102,20020110,20020111,20020112,20020200,20020201,20020210,20020211,20021000,20021001,20021010,20021011,20021100,20021101,20021110,20021111,20021200,20021201,20021210,20022000,20022010,20022100,20022110,20100000,20100001,20100002,20100010,20100011,20100012,20100020,20100021,20100022,20100100,20100101,20100110,20100111,20100120,20100121,20100200,20100201,20100210,20100211,20100220,20100221,20101000,20101001,20101002,20101010,20101011,20101012,20101100,20101101,20101110,20101111,20101200,20101201,20101210,20101211,20102000,20102001,20102002,20102010,20102011,20102012,20102100,20102101,20102110,20102111,20102200,20102210,20110000,20110001,20110002,20110010,20110011,20110012,20110020,20110021,20110022,20110100,20110101,20110110,20110111,20110120,20110121,20111000,20111001,20111010,20111011,20111100,20111101,20111110,20111111,20112000,20112001,20112010,20112011,20112100,20112110,20120000,20120001,20120002,20120010,20120011,20120012,20120100,20120101,20120110,20120111,20121000,20121001,20121100,20122000,20200000,20200001,20200002,20200010,20200011,20200012,20200020,20200021,20200022,20200100,20200101,20200110,20200111,20200120,20200121,20200200,20200210,20200220,20201000,20201001,20201002,20201010,20201011,20201012,20201100,20201101,20201110,20201111,20201200,20201210,20210000,20210001,20210002,20210010,20210011,20210020,20210021,20210100,20210101,20210110,20210111,20211000,20211001,20211010,20211011,20211100,20211110,20220000,20220001,20220002,20220010,20220011,20221000,20221001,21000000,21000001,21000002,21000010,21000011,21000020,21000021,21000100,21000101,21000102,21000110,21000111,21000200,21000201,21000202,21000210,21000211,21001000,21001001,21001002,21001010,21001011,21001020,21001021,21001100,21001101,21001102,21001110,21001111,21002000,21002001,21002002,21002010,21002011,21002020,21002021,21002100,21002101,21002102,21002110,21002111,21010000,21010001,21010002,21010010,21010011,21010020,21010021,21010100,21010101,21010102,21010110,21010111,21010200,21010201,21010202,21010210,21010211,21011000,21011001,21011010,21011011,21011020,21011100,21011101,21011110,21011111,21020000,21020001,21020002,21020010,21020011,21020100,21020101,21020102,21020200,21021000,21021001,21021010,21021100,21021101,21100000,21100001,21100002,21100010,21100011,21100020,21100021,21100100,21100101,21100110,21100111,21100200,21100201,21100210,21101000,21101001,21101002,21101010,21101011,21101100,21101101,21101110,21101111,21102000,21102001,21102002,21102010,21102011,21102100,21102101,21110000,21110001,21110002,21110010,21110011,21110020,21110021,21110100,21110101,21110110,21110111,21111000,21111001,21111010,21111011,21111100,21111101,21111110,21200000,21200001,21200002,21200010,21200011,21200020,21200100,21200101,21200110,21200200,21201000,21201001,21201002,21201010,21201011,21201100,21201101,21210000,21210001,21210002,21210010,21210011,21210020,21210100,21210101,21210110,22000000,22000001,22000002,22000010,22000011,22000020,22000100,22000101,22000102,22000110,22000111,22000200,22000201,22000202,22001000,22001001,22001002,22001010,22001011,22001020,22001100,22001101,22001102,22001110,22001111,22002000,22002001,22002010,22002011,22002020,22010000,22010001,22010002,22010010,22010011,22010020,22010100,22010101,22010110,22010111,22010200,22010201,22011000,22011001,22011010,22011100,22011101,22011110,22020000,22020001,22020002,22020010,22020011,22020100,22020101,22100000,22100001,22100002,22100010,22100011,22100020,22100100,22100101,22100110,22100200,22100201,22101000,22101001,22101002,22101010,22101011,22101100,22101101,22102000,22102001,22102010,22110000,22110001,22110002,22110010,22110011,22110020,22110100,22110101,22110110,22111000,22111001,22111010,30000000,30000001,30000010,30000011,30000100,30000101,30000110,30000111,30001000,30001001,30001010,30001011,30001100,30001101,30001110,30001111,30010000,30010001,30010010,30010011,30010100,30010101,30010110,30010111,30011000,30011001,30011010,30011011,30011100,30011101,30011110,30011111,30100000,30100001,30100010,30100011,30100100,30100101,30100110,30100111,30101000,30101001,30101010,30101011,30101100,30101101,30101110,30101111,30110000,30110001,30110010,30110011,30110100,30110101,30110110,30110111,30111000,30111001,30111010,30111011,30111100,30111110,31000000,31000001,31000010,31000011,31000100,31000101,31000110,31000111,31001000,31001001,31001010,31001011,31001100,31001101,31001110,31001111,31010000,31010001,31010010,31010011,31010100,31010101,31010110,31010111,31011000,31011001,31011010,31011100,31011101,31011110,31100000,31100001,31100010,31100011,31100100,31100101,31100110,31101000,31101001,31101010,31101011,31101100,31101101,31110000,31110001,31110010,31110011,31110100,31110101,31110110,31111000,31111001,31111010,100000000}; 12 const int SIZE=sizeof table/sizeof(int); 13 long long calc(const long long &x) { 14 long long sum=0,tmp=x; 15 while(tmp) { 16 sum+=tmp%10; 17 tmp/=10; 18 } 19 return sum; 20 } 21 int dfs(const long long &now,const int &r) { 22 if(now>r) return 0; 23 int ret=0; 24 if(calc(now)*calc(now)==calc(now*now)) ret++; 25 for(long long i=0;i<=3;i++) { 26 ret+=dfs(now*10+i,r); 27 } 28 return ret; 29 } 30 int main() { 31 freopen("snum.in","r+",stdin); 32 freopen("snum.out","w+",stdout); 33 int l=getint(),r=getint(); 34 if(r<=1e8) { 35 printf("%d\n",std::upper_bound(&table[0],&table[SIZE],r)-std::lower_bound(&table[0],&table[SIZE],l)); 36 return 0; 37 } 38 int ans=0; 39 if(l<=1e8) { 40 ans=1; 41 ans+=dfs(1,r); 42 ans+=dfs(2,r); 43 ans+=dfs(3,r); 44 ans-=std::lower_bound(&table[0],&table[SIZE],l)-&table[1]; 45 } else { 46 ans+=dfs(1,r); 47 ans+=dfs(2,r); 48 ans+=dfs(3,r); 49 ans-=dfs(1,l-1); 50 ans-=dfs(2,l-1); 51 ans-=dfs(3,l-1); 52 } 53 printf("%d\n",ans); 54 fclose(stdin); 55 fclose(stdout); 56 return 0; 57 }