8 条题解

  • 1
    @ 2024-12-20 22:11:17

    题解

    不难看出,此题无疑是一道水爆了的题,缘由在于其数据范围(n<100)( n < 100 )。 因此,我们仅需将ii的三个数位一次性分离出来并直接判断是否三位均不等于77即可。 C++代码实现如下:

    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define int long long
    #define float double
    #define N 30000010
    #define INF 0xc00000fd
    #define scf scanf
    #define ptf printf
    #define gtc getchar
    #define ptc putchar
    queue<int> Q;
    stack<int> S;
    vector<int> V;
    vector<int> travel(vector<int> A, vector<int> B, vector<int> U, vector<int> V, vector<int> W);
    #ifndef SOMETHING_H
    #define SOMETHING_H
    #endif
    inline int wei(int n){
    	int cnt = 0;
    	while(n > 0){
    		n /= 10;
    		cnt++;
    	}
    	return cnt;
    }
    inline bool isPrime(int n){
    	if(n < 2)
    		return 0;
    	for(int i = 2; i * i <= n; ++i)
    		if(n % i == 0)
    			return 0;
    	return 1;
    }
    inline int read(string n){
    	int x = 0, f = 1;
    	ptf("%s", n.c_str());
    	char c = gtc();
    	while(c < '0'  ||  c > '9'){
    		if(c == '-')
    			f = -1;
    		c = gtc();
    	}
    	while(c >= '0'  &&  c <= '9'){
    		x = x * 10 + c - 48;
    		c = gtc();
    	}
    	return x * f;
    }
    inline float input(string n){
    	float x = 0, f = 1, x2 = 0, cnt = 0, i = 0;
    	ptf("%s", n.c_str());
    	char c = gtc();
    	while(c < '0'  ||  c > '9'){
    		if(c == '-')
    			f = -1;
    		c = gtc();
    	}
    	while(c >= '0'  &&  c <= '9'){
    		x = x * 10 + c - 48;
    		c = gtc();
    	}
    	c = gtc();
    	while(c >= '0'  &&  c <= '9'){
    		x2 = x2 * 10 + c - 48;
    		cnt++;
    		c = gtc();
    	}
    	for(; i < cnt; i++)
    		x2 /= 10.0;
    	return (x + x2) * f;
    }
    inline void write(int n) {
        if(n < 0){
            ptc('-');
            n = -n;
        }
        if(n > 9)
    		write(n / 10);
        ptc(n % 10 + '0');
    	return;
    }
    inline void print(float n){
    	ptf("%.12lf\n", n);
    	return;
    }
    int n = read(""), sum;
    inline void Main(){
    	for(int i = 0; i < n; i++)
    		if(i / 10 - 7  &&  i % 10 - 7  &&  i % 7)
    			sum += i * i;
    	write(sum);
    	return;
    }
    signed main(signed argc, char **argv){
    	Main();
    	ptc('\n');
    	return 0;
    }
    
    • 0
      @ 2023-1-3 15:11:40
      #include<bits/stdc++.h>
      using namespace std;
      int n;
      int sum;
      int findd10_7(int x)
      {
      	while(x)
      	{
      		if(x%10==7)return 1;
      		x/=10;
      	}
      	return 0;
      }
      int finddi_7(int x)
      {
      	if(x%7==0)return 1;
      	return 0;
      }
      int main()
      {
      	cin>>n;
      	for(int i=1;i<=n;i++)
      	{
      		int x=findd10_7(i);
      		int y=finddi_7(i);
      		if(x+y==false)sum+=pow(i,2);
      	}
      	cout<<sum;
      	return 0;
      }
      
      • -1
        @ 2024-6-21 19:51:37

        #include <math.h> #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main() { int n, sum = 0; cin >> n; for(int i = 1; i <= n; i++) { if(i % 7 != 0) { int t = i; t /= 10; } if(t == 0)sum += i * i; } cout << sum; return 0; }

        • -1
          @ 2024-6-21 19:50:46

          #include <math.h> #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main() { int n, sum = 0; cin >> n; for(int i = 1; i <= n; i++) { if(i % 7 != 0) { int t = i; t /= 10; } if(t == 0)sum += i * i; } cout << sum; return 0; }

          • -1
            @ 2024-6-21 19:50:33

            #include <math.h> #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main() { int n, sum = 0; cin >> n; for(int i = 1; i <= n; i++) { if(i % 7 != 0) { int t = i; t /= 10; } if(t == 0)sum += i * i; } cout << sum; return 0; }

            • -1
              @ 2023-5-24 18:50:26

              #include<iostream> using namespace std; int n; int sum; int main() { cin>>n; for(int i=1;i<=n;i++){ if(i/10!=7&&i%10!=7&&i%7!=0)sum+=i*i; } cout<<sum; return 0; }

              • -1
                @ 2023-3-28 18:45:52
                #include<iostream>
                using namespace std;
                int n;
                long long sum;
                int main(){
                	cin>>n;
                	for(int i=1;i<=n;i++){
                		if(i/10!=7&&i%10!=7&&i%7!=0)sum+=i*i;
                	}
                	cout<<sum;
                	return 0;
                }
                
                • -2
                  @ 2022-7-21 19:07:36
                  #include <queue>
                  #include <math.h>
                  #include <stack>
                  #include <stdio.h>
                  #include <iostream>
                  #include <vector>
                  #include <iomanip>
                  #include <string.h>
                  #include <algorithm>
                  using namespace std;
                  #define LL long long
                  #define ull unsigned long long
                  const int N = 1e3 + 10;
                  const int INF = 0x3f3f3f3f;
                  int main()
                  {
                  	int n;
                  	cin >> n;
                  	int ans = 0;
                  	int sum = 0;
                  	int num = 0;
                  	for(int i = 1 ; i <= n ; i++)
                  	{
                  		sum = i / 10;
                  		num = i % 10;
                  		if(i % 7 == 0 || num == 7 || sum == 7)
                  			continue;
                  		else
                  			ans += i * i;
                  	}
                  	cout << ans << endl;
                  	return 0;
                  }
                • 1

                信息

                ID
                970
                时间
                1000ms
                内存
                128MiB
                难度
                4
                标签
                递交数
                376
                已通过
                178
                上传者