Skip to content

Instantly share code, notes, and snippets.

@mehmetaltuner
Created November 29, 2018 20:53
Show Gist options
  • Save mehmetaltuner/3b11ff29b55742cb8e9b1bee5f5a36c8 to your computer and use it in GitHub Desktop.
Save mehmetaltuner/3b11ff29b55742cb8e9b1bee5f5a36c8 to your computer and use it in GitHub Desktop.
typedef long long int lli;
lli pwr(lli a, lli b){
if(b == 1)
return a;
if(b == 0)
return 0;
lli sub_pwr = pwr(a, b/2);
if(b % 2 == 0)
return sub_pwr * sub_pwr;
return sub_pwr * sub_pwr * a;
}
lli substrings(string n){
lli len = n.size();
lli result = 0;
for(int i=len-1; i>-1; i--){
lli latest = n[i] - '0';
for(int j=i; j>-1; j--){
//cout << (((n[j] - '0') * pwr(10, i - j)) % mod) + latest << endl;
latest = (((n[j] - '0') * pwr(10, i - j)) % mod) + latest;
result += latest;
}
}
return result % mod;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment