2 条题解

  • 0
    @ 2023-7-10 9:58:20
    #include <iostream>
    #include <cstdio>
    #include <iomanip>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <stack>
    #include <queue>
    #define LL long long
    using namespace std;
    const int INF = 0x3f3f3f3f;
    const int N = 1e5 + 10;
    long long k , n;
    long long sum (int n , int m)
    {
    	if(m == 0)
    	{
    		return 1;
    	}
    	return n * sum(n , m - 1);
    }
    int main()
    {
    	cin >> n >> k;
    	int a[32];
    	int len = 0;
    	while( k )
    	{
    		a[len++] = k % 2;
    		k /= 2;
    	}
    	len--;
    	long long num = 0;
    	for(int i = 0; i <= len; i++)
    	{
    		if(a[i])
    		{
    			num += sum(n , i); 
    		}
    	}
    	cout << num << endl;
    	return 0;
    }
    
    • -3
      @ 2023-4-25 19:27:03
      #include<stdio.h>
      
      int n2[1010];
      long long l1 = 1;
      long long n, k;
      long long sm(long long i,long long k)
      {
      long long s = 1;
      int j;
      for (j = 1; j <= i; j++)
      {
      s *= k;
      }
      return s;
      }
      int main()
      {
      int i;
      scanf("%lld %lld",&k,&n);
      while(n > 0)
      {
      n2[l1++] = n % 2;
      n /= 2;
      }
      l1--;
      long long s = 0;
      for (i = 1; i <= l1; i++)
      {
      if (n2[i])
      {
      s += sm(i-1,k);
      }
      }
      printf("%lld",s);
      return 0;
      }
      
      • 1

      信息

      ID
      687
      时间
      1000ms
      内存
      256MiB
      难度
      5
      标签
      递交数
      71
      已通过
      30
      上传者