time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m.
Number x is considered close to number n modulo m, if:
Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him.
Input
The first line contains two integers: n (1?≤?n?1018) and m (1?≤?m?≤?100).
Output
In a single line print a single integer ? the number of numbers close to number n modulo m.
Sample test(s)
input
104 2
output
input
223 4
output
input
7067678 8
output
47
Note
In the first sample the required numbers are: 104, 140, 410.
In the second sample the required number is 232.
題意:給出一個數(shù)字num和m,問通過重新排列num中的各位數(shù)字中有多少個數(shù)(mod m)=0,直接枚舉全排列肯定不行,可以用狀壓dp來搞..
dp[S][k]表示選了num中的S且(mod m)=k的方案種數(shù),初始條件dp[0][0]=1,轉(zhuǎn)移方為dp[i|1<#include#include using namespace std;typedef long long ll;ll dp[1<<18][100],c[20];//dp[S][k]表示選了num中的S且(mod m)=k的方案種數(shù)int main(int argc, char const *argv[]){ char num[20]; int m; while(cin>>num>>m) { memset(dp,0,sizeof dp); memset(c,0,sizeof c); dp[0][0]=1; ll div=1,sz=strlen(num),t=1<
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com