Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- ll to_l(string s){
- ll r = 0;
- reverse(s.begin(), s.end());
- for (int i = 0; i < s.size(); ++i){
- ll pl = (s[i] - '0') * pow(10, i);
- r += pl;
- }
- return r;
- }
- ll f(ll x){
- cout<<"x = "<<x<<"\n";
- string s; s = to_string(x);
- cout<<"s = "<<s<<"\n";
- int z = s.find('0');
- //cout<<"z = "<<z<<"\n";
- if (z != -1) s = s.substr(0, z + 1);
- cout<<"s = "<<s<<"\n";
- ll a,b;
- //a = strtoll(s.c_str(), &endptr, 10);
- //a = strtoll(s, &end, 10);
- a = to_l(s);
- reverse(s.begin(), s.end());
- //b = strtoll(s.c_str(), &endptr, 10);
- //b = strtoll(s, &end, 10);
- b = to_l(s);
- cout<<"a b = "<<a<<' '<<b<<"\n";
- return min(a,b);
- }
- /*
- 142
- char* endptr = NULL;
- user3 = strtoll(str.c_str(), &endptr, 10);
- */
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- ll n,k,ans=0;
- cin>>n>>k;
- string s = to_string(k);
- reverse(s.begin(), s.end());
- ll abc = k;
- //ll cba = strtoll(s.c_str(), &endptr, 10);
- //ll cba = strtoll(s, &end, 10);
- ll cba = to_l(s);
- int pow10 = log10(n);
- if (n == k && f(n) == k){//???
- cout<<1;
- exit(0);
- }
- else if (n == k){
- cout<<0;
- exit(0);
- }
- if (cba >= abc && k <= n){
- ans+=2;
- }
- for (int i = 1; i <= pow10;++i){
- ll A,B;
- A = abc * pow(10, i);
- B = cba * pow(10, i);
- if (A <= n && A >= k){
- ans++;
- }
- if (B <= n && B >= k){
- ans++;
- }
- }
- //cout<<ans<<"\n";
- ll ch=0;
- for (ll i = 1;i<=n;++i){
- if (i >= k && f(i) == k){
- ch++;
- }
- }
- cout<<"ch ans = "<<ch<<' '<<ans<<"\n";
- }
Add Comment
Please, Sign In to add comment