Problem:
Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

!function(t){var e={};function n(r){if(e[r])return e[r].exports;var u=e[r]={i:r,l:!1,exports:{}};return t[r].call(u.exports,u,u.exports,n),u.l=!0,u.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var u in t)n.d(r,u,function(e){return t[e]}.bind(null,u));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},u=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var i=r(n(28)),o=u(n(29));e.paizaInput=function(){process.stdin.resume(),process.stdin.setEncoding("utf8");var t=[],e=o.createInterface({input:process.stdin,output:process.stdout});return e.on("line",function(e){t.push(e)}),new Promise(function(n){e.on("close",function(){n(t)})})},e.hackerRankInput=function(){process.stdin.resume(),process.stdin.setEncoding("ascii");var t="";return process.stdin.on("data",function(e){t+=e}),new Promise(function(e){process.stdin.on("end",function(){e(t.split("\n"))})})},e.atcoderInput=function(){return i.default.readFileSync("/dev/stdin","utf8")}},function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(u,i){function o(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?u(t.value):new n(function(e){e(t.value)}).then(o,a)}c((r=r.apply(t,e||[])).next())})},u=this&&this.__generator||function(t,e){var n,r,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(u=2&i[0]?r.return:i[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,i[1])).done)return u;switch(r=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=(u=o.trys).length>0&&u[u.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],r=0}finally{n=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=i(n(2)),a=n(0);!function(){r(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return[4,a.paizaInput()];case 1:return t=e.sent(),o.default.beginner_contest_142.d(t).forEach(function(t){return console.log(t)}),[2]}})})}()},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(3)),i=r(n(7)),o=r(n(10)),a=r(n(14)),c=r(n(19)),f=r(n(22)),l=r(n(25)),s=r(n(27)),d=r(n(30));e.default={beginner_contest_122:u.default,beginner_contest_126:i.default,beginner_contest_133:o.default,beginner_contest_142:a.default,Diverta2019ProgrammingContest:c.default,GrandContest029:f.default,GrandContest035:l.default,interactiveSorting:s.default,welcomeToAtCoder:d.default}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(4)),i=r(n(5)),o=r(n(6));e.default={A_DoubleHelix:u.default,B_ATCoder:i.default,C_GeT_AC:o.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){switch(t[0]){case"A":return["T"];case"T":return["A"];case"C":return["G"];case"G":return["C"];default:throw new Error("invalid string")}}},function(t,e,n){"use strict";function r(t){return"A"===t||"T"===t||"C"===t||"G"===t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){for(var e=t[0],n=0,u=0,i=0;u<e.length;u+=1)r(e[u])?i+=1:i>n&&(n=i,i=0);return i>n&&(n=i),[String(n)]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t[0].split(" ").map(function(t){return Number(t)}),n=(e[0],e[1],t[1]),r=t.slice(2).map(function(t){return t.split(" ").map(function(t){return Number(t)})}),u=n.split("").map(function(t,e,n){return"A"===t&&n.length>e+1&&"C"===n[e+1]});return r.map(function(t){for(var e=t[0],n=t[1],r=0,i=e-1;i<n-1;i+=1)u[i]&&(r+=1);return String(r)})}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(8)),i=r(n(9));e.default={a:u.default,b:i.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t[0].split(" ").map(function(t){return Number(t)}),n=(e[0],e[1]);return[t[1].split("").map(function(t,e){return e===n-1?t.toLowerCase():t}).join("")]}},function(t,e,n){"use strict";function r(t){return 1<=t&&t<=12}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t[0],n=Number(e.slice(0,2)),u=Number(e.slice(2,4)),i=r(n),o=r(u);return i&&o?["AMBIGUOUS"]:!i&&o?["YYMM"]:i&&!o?["MMYY"]:["NA"]}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(11)),i=r(n(12)),o=r(n(13));e.default={b:u.default,c:i.default,d:o.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(t){return t.reduce(function(t,e,n,r){return t+e})};e.default=function(t){for(var e=t[0].split(" ").map(function(t){return Number(t)}),n=(e[0],e[1],t.slice(1).map(function(t){return t.split(" ").map(function(t){return Number(t)})})),u=0,i=0;i<n.length;i+=1)for(var o=function(t){var e,o=n[i],a=n[t];e=Math.sqrt(r(o.map(function(t,e){return Math.pow(t-a[e],2)}))),Math.round(e)===e&&(u+=1)},a=i+1;a<n.length;a+=1)o(a);return[u.toString()]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e,n,r=t[0].split(" ").map(function(t){return Number(t)}),u=r[0],i=r[1];Math.ceil(u/2019)===Math.ceil(i/2019)?(e=u%2019,n=i%2019):(e=u%2019,n=i%2019+2019);for(var o=2019,a=e;a<=n;a+=1)for(var c=a+1;c<=n;c+=1){var f=a*c%2019;f<o&&(o=f)}return[o.toString()]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){Number(t[0]);for(var e=t[1].split(" ").map(function(t){return Number(t)}),n=0;n<=2*e[0];n+=2){for(var r=n,u=void 0,i=!0,o=[],a=0;a<e.length;a+=1){if((u=e[a]-r)<0){i=!1;break}o.push(r),r=u}if(i&&2*e[e.length-1]===o[0]+o[o.length-1])return[o.map(function(t){return t.toString()}).join(" ")]}return[]}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(15)),i=r(n(16)),o=r(n(17)),a=r(n(18));e.default={a:u.default,b:i.default,c:o.default,d:a.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=Number(t[0]),n=Math.floor(e/2)+(e%2==1?1:0);return[String(n/e)]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t[0].split(" ").map(function(t){return Number(t)}),n=(e[0],e[1]),r=t.slice(1).map(function(t){return t.split(" ").map(function(t){return Number(t)})})[0].filter(function(t){return t>=n});return[String(r.length)]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){t[0].split(" ").map(function(t){return Number(t)})[0];var e=t.slice(1).map(function(t){return t.split(" ").map(function(t){return Number(t)})})[0],n=e.map(function(t){return-1});return e.forEach(function(t,e){return n[t-1]=e+1}),[n.join(" ")]}},function(t,e,n){"use strict";function r(t,e,n){for(var r=!1,u=n,i=0;i<e.length;i+=1)if(1!==e[i]&&t%e[i]==0){r=!0;break}return r||(u+=1,e.push(t)),{array:e,flag:r,count:u}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){for(var e=t[0].split(" ").map(function(t){return Number(t)}),n=e[0],u=e[1],i=n>u?[n,u]:[u,n],o=i[0],a=i[1],c=Math.sqrt(a),f=0,l=[],s=1;s<=c;s+=1){var d;o%s==0&&a%s==0&&(f=(d=r(s,l,f)).count,l=d.array)}return 1!==a&&(f=(d=r(a,l,f)).count,l=d.array),[f.toString()]}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(20)),i=r(n(21));e.default={c:u.default,d:i.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){t[0].split(" ").map(function(t){return Number(t)})[0];var e=t.slice(1),n=0,r=0,u=0,i=0;return e.forEach(function(t,e){"B"===t[0]&&(u+=1),"A"===t[t.length-1]&&(r+=1),"B"===t[0]&&"A"===t[t.length-1]&&(i+=1),n+=(t.match(/AB/g)||[]).length}),r-i==0&&u-i==0?[String(n+i-1)]:[String(r<u?r+n:u+n)]}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){for(var e=t[0].split(" ").map(function(t){return Number(t)})[0],n=0,r=Math.sqrt(e),u=1;u<r;u+=1){var i=(e-u)/u;Number.isInteger(i)&&(n+=i)}return[String(n)]}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(23)),i=r(n(24));e.default={AIrreversibleOperation:u.default,BPowerOfTwo:i.default}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=!0,u=!1;function i(t){var e=function(t){for(var e=[],n=0;n<t.length-1;n+=1)t[n]===r&&t[n+1]===u&&e.push(n);return e}(t);return 0===e.length?0:1+Math.max.apply(Math,e.map(function(e){return i(function(t,e){var n=t.concat();return n[e]=!n[e],n[e+1]=!n[e+1],n}(t,e))}))}e.default=function(t){return[i(t[0].split("").map(function(t){return"B"===t}))]}},function(t,e,n){"use strict";function r(t){return t.length<2?0:Math.max.apply(Math,t.map(function(e,n){var u=t.filter(function(t,e){return e!==n});return Math.max.apply(Math,u.map(function(t,n){return function(t,e){var n=t+e;return 0==(n&n-1)}(e,t)?r(u.filter(function(t,e){return e!==n}))+1:0}))}))}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){Number(t[0]);var e=function(t){var e=t.filter(function(t){return t%2==1}),n=t.filter(function(t){return t%2==0});return{odds:e,evens:n}}(t[1].split(" ").map(function(t){return Number(t)})),n=e.odds,u=e.evens;return[r(n)+r(u)]}},function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var u=r(n(26));e.default={a:u.default}},function(t,e,n){"use strict";function r(t,e,n){return(t^e)===n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){t[0].split(" ").map(function(t){return Number(t)})[0];var e=t[1].split(" ").map(function(t){return Number(t)});return[function t(e,n){if(0===n.length){var u=e.length;return r(e[u-2],e[0],e[u-1])&&r(e[u-1],e[1],e[0])?{array:e,ok:!0}:{array:[],ok:!1}}for(var i=0;i<n.length;i+=1){var o=n[i],a=e[e.length-1];if(e.length<2){var c=e.map(function(t){return t});c.push(o);var f=n.map(function(t){return t});f.splice(i,1);var l=t(c,f);if(l.ok)return l}else{var s=e[e.length-2];if(r(o,s,a)){var c=e.map(function(t){return t});c.push(o);var f=n.map(function(t){return t});f.splice(i,1);var l=t(c,f);if(l.ok)return l}}}return{array:[],ok:!1}}([e[0]],e.slice(1)).ok?"Yes":"No"]}},function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(u,i){function o(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?u(t.value):new n(function(e){e(t.value)}).then(o,a)}c((r=r.apply(t,e||[])).next())})},u=this&&this.__generator||function(t,e){var n,r,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(u=2&i[0]?r.return:i[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,i[1])).done)return u;switch(r=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=(u=o.trys).length>0&&u[u.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],r=0}finally{n=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(0);function o(t){return r(this,void 0,void 0,function(){var e,n,r,i,c,f;return u(this,function(u){switch(u.label){case 0:return 1===t.length?[2,t]:(e=t.slice(0,Math.ceil(t.length/2)),n=t.slice(Math.ceil(t.length/2)),[4,o(e)]);case 1:return r=u.sent(),[4,o(n)];case 2:i=u.sent(),c=[],u.label=3;case 3:return r.length>0&&i.length>0?[4,a(r[0],i[0])]:[3,5];case 4:return(f=u.sent()?r.shift():i.shift())&&c.push(f),[3,3];case 5:return c.push.apply(c,r.concat(i)),[2,c]}})})}function a(t,e){return r(this,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return console.log("? "+t+" "+e),[4,i.atcoderInput()];case 1:return[2,"<"===n.sent()]}})})}e.default=function(t){return r(this,void 0,void 0,function(){var e,n,r;return u(this,function(u){switch(u.label){case 0:return e=t[0].split(" ").map(function(t){return Number(t)}),n=e[0],e[1],r="A".charCodeAt(0),[4,o(Array.apply(null,new Array(n)).map(function(t,e){return String.fromCharCode(r+e)}))];case 1:return[2,["! "+u.sent().join("")]]}})})}},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("readline")},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=Number(t[0]),n=t[1].split(" ").map(function(t){return Number(t)});return[e+n[0]+n[1]+" "+t[2]]}}]);
//# sourceMappingURL=main.js.map