各位大佬,我想问一下哪里错了?

baojiya 2022-06-17 21:02:45 2022-06-17 21:37:13 0
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, a = 0, t;
    scanf("%d%d", &n, &m);
    t = m / 2;
    for (int a = 1; a <= t; a++) {
        if (N % a == 0 && (N % (M - a) == 0)) {
            t = -1;
            break;
        }
    }
    if (t != -1)
        printf("-1");
    else
        printf("%d", a);

    return 0;
}
编译信息
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:9:6: error: 'N' was not declared in this scope
    9 |   if(N%a==0 && (N%(M-a)==0)) { t=-1; break; }
      |      ^
/sandbox/1/a.cpp:9:20: error: 'M' was not declared in this scope
    9 |   if(N%a==0 && (N%(M-a)==0)) { t=-1; break; }
      |                    ^
/sandbox/1/a.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
{{ vote && vote.total.up }}

共 7 条回复

root 站长

n,m都是小写的,你后面写了大写N,M

CPP 刷题王
#include <bits/stdc++.h>
using namespace std;
int main() {
	int t, n, m;
	cin >> t;
	while(t--) {
		scanf("%d%d", &n, &m);
		int ans = 0;
		for(int i = 1; i <= n; i++) {
			if(m % i == 0 && m / i <= n) {
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
baojiya

...好的

CPP 刷题王

再发一次

baojiya

感谢大佬

CPP 刷题王

哪道题

CPP 刷题王

请在代码前用```cpp